mercredi 3 juillet 2019

Numpy replacing elements based on logic and value in an identically shaped array

I have 2 numpy arrays. One is filled with boolean values and the other numerical values.

How would I perform logic on the numerical array based on also the current value in the boolean array.

e.g. if true and > 5 then make the value false

matrix1
matrix2

newMatrix = matrix1 > 5 where matrix2 value is false

Please note that these arrays have the same shape e.g.

[[0, 1, 1],  
[1, 0, 0]]

and

[[3, 1, 0]  
[6, 2, 6]]

And the result I would like would be a new boolean matrix that is true if its value is true in the boolean array and the equivalent value in the numerical array is more than 5 e.g.

[[0, 0, 0]  
[1, 0, 0]]

Aucun commentaire:

Enregistrer un commentaire