jeudi 18 avril 2019

How to generate bounded random array based on mean and standard deviation of another array?

I have an array X containing R rows and C columns. I wish to generate a new array named a_array where each element will be randomly generated based on the mean and standard deviation of its corresponding row in X. What is the most pythonic and efficient way to do this using Numpy?

Currently, I am using a nested loop to generate element-wise numbers.

a_array = np.zeros(shape=(a_size, X.shape[0]))
for i in range(a_size):
    for j in range(X.shape[0]):
        a_array[i][j] = np.random.randint(low=X[i].mean()-X[i].std(), high=X[i].mean()+X[i].std())




Aucun commentaire:

Enregistrer un commentaire