consider the array a
a = np.array([3, 3, np.nan, 3, 3, np.nan])
I could do
np.isnan(a).argmax()
But this requires finding all np.nan
just to find the first.
Is there a more efficient way?
I've been trying to figure out if I can pass a parameter to np.argpartition
such that np.nan
get's sorted first as opposed to last.
EDIT regarding [dup].
There are several reasons this question is different.
- That question and answers addressed equality of values. This is in regards to
isnan
. - Those answers all suffer from the same issue my answer faces. Note, I provided a perfectly valid answer but highlighted it's inefficiency. I'm looking to fix the inefficiency.
EDIT regarding second [dup].
Still addressing equality and question/answers are old and very possibly outdated.