Simple way to create matrix of random numbers

前端 未结 13 1695
灰色年华
灰色年华 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:03

    Looks like you are doing a Python implementation of the Coursera Machine Learning Neural Network exercise. Here's what I did for randInitializeWeights(L_in, L_out)

    #get a random array of floats between 0 and 1 as Pavel mentioned 
    W = numpy.random.random((L_out, L_in +1))
    
    #normalize so that it spans a range of twice epsilon
    W = W * 2 * epsilon
    
    #shift so that mean is at zero
    W = W - epsilon
    

提交回复
热议问题