SyntaxFix
Write A Post
Hire A Developer
Questions
For 1D arrays, I'd recommend np.flatnonzero(array == value)[0], which is equivalent to both np.nonzero(array == value)[0][0] and np.where(array == value)[0][0] but avoids the ugliness of unboxing a 1-element tuple.
np.flatnonzero(array == value)[0]
np.nonzero(array == value)[0][0]
np.where(array == value)[0][0]