SciPy

scipy.sparse.dia_matrix.getnnz

dia_matrix.getnnz()[source]

number of nonzero values

explicit zero values are included in this number