SciPy

scipy.sparse.dok_matrix.nnz

property dok_matrix.nnz

Number of stored values, including explicit zeros.

See also

count_nonzero

Number of non-zero entries