NumPy Boolean Array in Index

Viewed 66

Say we have two arrays

a = np.array([1,2,3,4]).reshape(2,2)
b = np.array([True, False, False, True]).reshape(2,2)

gives

a = [[1, 2],
     [3, 4]] 
b = [[True, False],
     [False, True]]

We can do a[b] to get only the values of b that are true giving us [1, 4]

I tried to do a[not b] to get those that are false but got an error. I know I can do a[b == False] but want to do it in a Pythonic way.

Any solution?

1 Answers
Related