numpy zero nan code example Example 1: numpy is not nan a = a[~np.isnan(a)] Example 2: python zeros to nan a[a==0] = np.nan