Reputation: 149
I have this code where I want to reference all elements of m in matlab:
NNanm = sum(isnan(m(:)));
How would I tell python to reference all the elements of m?
Upvotes: 2
Views: 1322
Reputation: 24268
If I understand your code correctly, you count all nan elements in the matrix. If so, you can do the equivalent thing in python this using numpy with the following code:
import numpy as np
np.count_nonzero(np.isnan(m))
If you insist on the sum
function, this also work:
np.sum(np.isnan(m))
Upvotes: 5