Use numpy.argwhere to obtain the matching values in an np.array

Viewed 28015

I'd like to use np.argwhere() to obtain the values in an np.array.

For example:

z = np.arange(9).reshape(3,3)

[[0 1 2]
 [3 4 5]
 [6 7 8]]

zi = np.argwhere(z % 3 == 0)

[[0 0]
 [1 0]
 [2 0]]

I want this array: [0, 3, 6] and did this:

t = [z[tuple(i)] for i in zi] # -> [0, 3, 6]

I assume there is an easier way.

2 Answers
Related