SciPy

scipy.sparse.csr_matrix.getnnz

csr_matrix.getnnz(axis=None)[source]

Get the count of explicitly-stored values (nonzeros)

Parameters:

axis : {None, 0, 1}, optional

Select between the number of values across the whole matrix, in each column, or in each row.