mercredi 22 décembre 2021

How to add random numbers on a numpy array?

I want to add random numbers between my numpy array. I want 2000 new numbers on a index in my numpy array. The numbers should be added over the second axis. The old random numbers should not be overwritten, they should stay and the new numbers should be added on a random place between them. Could you please help me with that?

That is what I have so far:

z = np.random.randint(40, 200, (40, 24))
for index_i, i in enumerate(z):
    for index_j, j in enumerate(i):
        #if the index is the first 6 (0-6) or the last 2 (22 and 23) make it random between 0 and 50
        if index_j in [0, 1, 2, 3, 4, 5, 6, 22, 23]:
            z[index_i][index_j] = np.random.randint(0, 50)



Aucun commentaire:

Enregistrer un commentaire