arrays – isnotnan functionality in numpy, can this be more pythonic?

arrays – isnotnan functionality in numpy, can this be more pythonic?

a = a[~np.isnan(a)]

You are currently testing for anything that is not NaN and mtrw has the right way to do this. If you are interested in testing for finite numbers (is not NaN and is not INF) then you dont need an inversion and can use:

np.isfinite(a)

More pythonic and native, an easy read, and often when you want to avoid NaN you also want to avoid INF in my experience.

Just thought Id toss that out there for folks.

arrays – isnotnan functionality in numpy, can this be more pythonic?

Im not sure whether this is more or less pythonic…

a = [i for i in a if i is not np.nan]

Leave a Reply

Your email address will not be published. Required fields are marked *