jeudi 21 janvier 2021

adding random values in a specific column in a multidimensional-array

i need to add random values in a large mxn matrix, only in the first column. has somebody an idea how it works?

import numpy as np

f = lambda m, n:n+np.random.rand(1)*m

# create a mxn matrix 
A = np.fromfunction(f,(6,6), dtype=int)

# create random value that have to be added in the 1st column of the mxn matrix
random = np.random.rand(len(A[:,1]))

print(A)

# in this case, the random values are added in each of the columns
print(random + A)



Aucun commentaire:

Enregistrer un commentaire