如何使用np.random.seed()创建具有固定随机值的新矩阵

时间:2017-08-21 06:50:30

标签: python numpy matrix

我想在每个位置创建具有固定随机值的新矩阵(V)(每次运行算法时,我希望显示相同的矩阵)。是否可以将np.random.seed()用于矩阵?像

这样的东西
V = np.zeros([20,50])
V = np.random.seed(V)

1 个答案:

答案 0 :(得分:3)

使用它来设置种子:

np.random.seed(0) # or whatever value you fancy

然后生成随机数据:

V = np.random.rand(your_shape) # or whatever randomness you fancy like randint, randn ...