## Fix Python – Counting the number of non-NaN elements in a numpy ndarray in Python

I need to calculate the number of non-NaN elements in a numpy ndarray matrix. How would one efficiently do this in Python? Here is my simple code for achieving this:

import numpy as np

def numberOfNonNans(data):

count = 0

for i in data:

if not np.isnan(i):

count += 1

return count

Is there a built-in function for….