Find if array of arrays contains more than 1 nan element?
I want to find if conf_int_arr has more than 1 [nan, nan] array, how can i do that?
conf_int_arr = [array([nan, nan]),
array([39.49, 57.08]),
array([nan, nan]),
array([nan, nan])]
I searched the solution but this not works.
np.where(conf_int_arr != conf_int_arr.round())
You can simply convert your list to a numpy array and then count the rows which only contain nan values:
import numpy as np
conf_int_arr = [np.array([np.nan, np.nan]),
np.array([39.49, 57.08]),
np.array([np.nan, np.nan]),
np.array([np.nan, np.nan])]
conf_int_arr = np.array(conf_int_arr)
result = np.isnan(conf_int_arr).all(axis=1).sum()
print(result)
Output:
3
I am not sure if this is the most efficient way to do it but it works.
import numpy as np
conf_int_arr = [
np.array([np.nan, np.nan]),
np.array([39.49, 57.08]),
np.array([np.nan, np.nan]),
np.array([np.nan, np.nan]),
]
nan_array = np.array([np.nan, np.nan])
print(np.sum([np.array_equal(each_array, nan_array, equal_nan=True) for each_array in conf_int_arr]))