Simple way to create matrix of random numbers

前端 未结 13 1680
灰色年华
灰色年华 2020-12-12 21:20

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 ra         


        
13条回答
  •  情歌与酒
    2020-12-12 22:02

    You can drop the range(len()):

    weights_h = [[random.random() for e in inputs[0]] for e in range(hiden_neurons)]
    

    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]])
    

提交回复
热议问题