numpy find columns containing nan 1

numpy find columns containing nan

# in each case returns array of bool
np.isnan(a).any(axis=0) # columns where any value is nan
np.isnan(a).all(axis=0) # columns where all values are nan

Here is what the above code is Doing:
1. np.isnan(a) returns a boolean array of the same shape as a, where True indicates a value is nan.
2. np.isnan(a).any(axis=0) returns a boolean array of the same shape as a, where True indicates that any value in the column is nan.
3. np.isnan(a).all(axis=0) returns a boolean array of the same shape as a, where True indicates that all values in the column are nan.

Similar Posts