COO.nnz

COO.nnz

The number of nonzero elements in this array. Note that any duplicates in coords are counted multiple times. To avoid this, call COO.sum_duplicates.

Returns:

The number of nonzero elements in this array.

Return type:

int

See also

DOK.nnz

Equivalent DOK array property.

numpy.count_nonzero

A similar Numpy function.

scipy.sparse.coo_matrix.nnz

The Scipy equivalent property.

Examples

>>> x = np.array([0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 0])
>>> np.count_nonzero(x)
6
>>> s = COO.from_numpy(x)
>>> s.nnz
6
>>> np.count_nonzero(x) == s.nnz
True