我试图生成可能很大的浮点数数组(0.0-1.0),但每个元素都由一个种子数组驱动,该数组由整数组成,表示一个id。
例如,如果我有这两个数组:
seedArray1 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
seedArray2 = np.array([0, 1, 2, 3, 4, 5])
我希望能够使用这些数组作为种子,但是当两个数组中的元素相同时(不管数组的形状或长度如何,或该ID在数组中出现的位置),它们应该生成相同的浮点数,就像这样:
[ 0.5488135 0.417022 0.4359949 0.5507979 0.96702984 0.22199317 0.89286015 0.07630829 0.8734294 0.01037415]
[ 0.5488135 0.417022 0.4359949 0.5507979 0.96702984 0.22199317]
然而,当我尝试设置numpy.random的随机种子时,我得到了不同的结果:
import numpy as np
x1 = np.arange(10)
x2 = np.arange(6)
np.random.seed(x1)
print np.random.rand(x1.shape[0])
np.random.seed(x2)
print np.random.rand(x2.shape[0])
以下内容会被打印出来:
[ 0.41060638 0.23192123 0.91382737 0.02916066 0.91437242 0.51045425 0.26140116 0.16574922 0.08861477 0.31908955]
[ 0.52500897 0.98236732 0.99371835 0.14121932 0.66945133 0.24223304]
有没有一种方法可以生成随机的numpy数组,使用每个元素作为种子,并仍然利用numpy的速度?