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

Ian Stokes-Rees ijstokes@hkl.hms.harvard....
Wed Dec 22 15:10:05 CST 2010



On 12/22/10 9:16 AM, Ian Stokes-Rees wrote:
> What is the most efficient way to do the Matlab equivalent of nnz(M)
> (nnz = number-of-non-zeros function)?

Thanks to all the various responses.  I should have mentioned that I'm
using scipy.sparse, and lil_matrix objects have a method "getnnz()"
which gives me the number I want.

Ian


More information about the NumPy-Discussion mailing list