Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用np.random.seed()创建具有固定随机值的新矩阵_Python_Numpy_Matrix - Fatal编程技术网

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

Python 如何使用np.random.seed()创建具有固定随机值的新矩阵,python,numpy,matrix,Python,Numpy,Matrix,我想创建一个新的矩阵(V),每个位置都有固定的随机值(每次我运行算法时,我都想显示相同的矩阵)。可以对矩阵使用np.random.seed()吗?差不多 V = np.zeros([20,50]) V = np.random.seed(V) 使用此选项设置种子: np.random.seed(0) # or whatever value you fancy 然后生成随机数据: V = np.random.rand(your_shape) # or whatever randomness yo

我想创建一个新的矩阵(V),每个位置都有固定的随机值(每次我运行算法时,我都想显示相同的矩阵)。可以对矩阵使用np.random.seed()吗?差不多

V = np.zeros([20,50])
V = np.random.seed(V)

使用此选项设置种子:

np.random.seed(0) # or whatever value you fancy
然后生成随机数据:

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

使用此选项设置种子:

np.random.seed(0) # or whatever value you fancy
然后生成随机数据:

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

请更详细地解释你所说的“每次具有一致随机值的新矩阵”是什么意思。请更详细地解释你所说的“每次具有一致随机值的新矩阵”是什么意思。我尝试了一下,发现括号中的数字是
np.random.seed(0)
表示随机性的版本?请问这个数字为什么重要?我的意思是,当我编写新的
np.random.seed()
时,我认为所有版本都是重新创建的。这个数字以后可以重复使用吗?@Jan:这个参数完全由您决定,但您可以放心,这个数字将保证任何实现的一致性。@Jan,
np.random.seed()
将以不受控制的方式重置(伪)随机数生成器的种子(从而重置状态)(通常从当前开始,当您希望确保每次运行都会产生不同的结果时使用此选项)。为确保重复性,您需要使用
np.random.seed(1234)
或等效项指定种子。我尝试了此选项,并在
np.random.seed(0)的括号中找到了数字
表示随机性的版本?我可以问一下为什么这个数字很重要吗?我的意思是当我写新的
np.random.seed()时
,我想所有的版本都被重新创建了。这个数字是可以重用的还是以后的事情?@Jan:这个参数完全由您决定,但您可以放心,这个数字将保证任何实现的一致性。@Jan,
np.random.seed()
将重置您的(伪-)的种子(因此是状态)随机数生成器,但以不受控制的方式(通常从当前时间开始,当您希望确保每次运行都会产生不同的结果时使用)。使用
np.random.seed(1234)
或等效项指定种子是确保可重复性所需的。