2

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?

1
  • 1
    Use m[:] not m(:). Commented Feb 8, 2016 at 0:39

1 Answer 1

5

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.