Counting the number of non-NaN elements in a numpy ndarray matrix in Python,np.count_nonzero(~np.isnan(data))