SciPy

scipy.sparse.dia_matrix.nnz

dia_matrix.nnz

number of nonzero values

explicit zero values are included in this number