[Numpy-discussion] counting non-zero entries in an ndarray

Ian Stokes-Rees ijstokes at hkl.hms.harvard.edu
Wed Dec 22 09:16:17 EST 2010


What is the most efficient way to do the Matlab equivalent of nnz(M)
(nnz = number-of-non-zeros function)?

I've tried Google, but no luck.

My assumption is that something like

a != 0

will be used, but I'm not sure then how to "count" the number of "True"
entries.

TIA.

Ian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ijstokes.vcf
Type: text/x-vcard
Size: 380 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20101222/03855a06/attachment.vcf>


More information about the NumPy-Discussion mailing list