SciPy

scipy.sparse.lil_matrix.getnnz

lil_matrix.getnnz()[source]