Getting The First Occurrence Of A Value In An N-dimensional Numpy Array
I have seen this question, but want to reduce the array created from mask = array == value mask = array([[[ True, True, True], [False, True, True]],
Solution 1:
Actually, it's as simple as this:
np.argmax(mask, 2)
Example:
In [15]: %paste
mask = array([[[ True, True, True],
[False, True, True]],
[[False, True, True],
[False, True, True]],
[[False, False, True],
[False, True, True]]])
## -- End pasted text --
In [16]: np.argmax(mask, 2)
Out[16]:
array([[0, 1],
[1, 1],
[2, 1]], dtype=int64)
Post a Comment for "Getting The First Occurrence Of A Value In An N-dimensional Numpy Array"