mercredi 16 août 2017

Writing a loop that chooses random values from columns - Python

Created a 2d array with (170,10) shape

i = np.array(range(1,1701)).reshape(170,10)

Want to write a loop that choses 5 random values without replacement from each column (or n number of columns) of i and output as below:

Group 1: [  7  37 124  41  17]
Group 2: [302 261 257 323 234]
Group 3: [464 486 463 440 474]

So far i can pull random values from a single column:

print(np.random.choice(i[:,0],5 ,replace=False))

How do i put this in a for loop and pull for n number of columns with the displayed output (will use .function for that)




Aucun commentaire:

Enregistrer un commentaire