SciPy

scipy.sparse.csr_matrix.count_nonzero

csr_matrix.count_nonzero(self)[source]

Number of non-zero entries, equivalent to

np.count_nonzero(a.toarray())

Unlike getnnz() and the nnz property, which return the number of stored entries (the length of the data attribute), this method counts the actual number of non-zero entries in data.

Previous topic

scipy.sparse.csr_matrix.copy

Next topic

scipy.sparse.csr_matrix.deg2rad