创建随机数矩阵的简单方法 [英] Simple way to create matrix of random numbers
本文介绍了创建随机数矩阵的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个随机数矩阵,但我的解决方案太长了,看起来很丑陋
I am trying to create a matrix of random numbers, but my solution is too long and looks ugly
random_matrix = [[random.random() for e in range(2)] for e in range(3)]
这看起来确定,但在我的实现是
this looks ok, but in my implementation it is
weights_h = [[random.random() for e in range(len(inputs[0]))] for e in range(hiden_neurons)]
推荐答案
您可以放置范围(len())
:
You can drop the range(len())
:
weights_h = [[random.random() for e in inputs[0]] for e in range(hiden_neurons)]
但实际上你应该可以使用numpy。
But really, you should probably use numpy.
In [9]: numpy.random.random((3, 3))
Out[9]:
array([[ 0.37052381, 0.03463207, 0.10669077],
[ 0.05862909, 0.8515325 , 0.79809676],
[ 0.43203632, 0.54633635, 0.09076408]])
这篇关于创建随机数矩阵的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文