For example, I have this array and calculate mean of rows:
a = np.array([[1,2,3],[2,np.NaN,4]])
mins = np.min(a, axis = 1)
The problem is the output is: [1. nan]
. How to ignore nan in a and get result [1 2]
?
You can use masked arrays
mins = list(np.min(np.ma.masked_array(a, np.isnan(a)), axis=1))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments