mercredi 29 mai 2019

How can I pick random value in matrix using conditions

Hi I have to extract some data from my matrix whitout looping using numpy

here is a given matrix at the end of my code:

[[1 3][1 --][2 3][3 --][1 --][3 --][2 --][1 --][1 --][1 3]]

At the end I must get one matrix like this :

[[1 ] [1 ] [3 ] [3 ] [1 ] [3 ] [2 ] [1 ] [1 ] [3 ]]

I would like to select random value when there is no value: -- (exemple [1 3]) and pick the only value available when there is -- value (exemple [1 --]).

I must avoid using loop and all the result are randomly generated between 1 and 3.

Thank you for your help! np.count_nonzero(Resultat, axis=1)




Aucun commentaire:

Enregistrer un commentaire