Create a mask both for nan and inf values in an array
You can use np.isfinite()
. It will return a boolean mask with True
wherever the values are neither infinite nor NAN.
You can get the finite values this way:
a = np.asarray(a)
a = a[np.isfinite(a)]
Or for both arrays together:
mask = np.isfinite(a) | np.isfinite(b)
a = a[mask]
b = b[mask]
np.isfinite
Test element-wise for finiteness (not infinity or not Not a Number).