unique_counts

sparse.unique_counts(x, /)[source]

Returns the unique elements of an input array x, and the corresponding counts for each unique element in x.

Parameters:

x (COO) – Input COO array. It will be flattened if it is not already 1-D.

Returns:

out – The result containing: * values - The unique elements of an input array. * counts - The corresponding counts for each unique element.

Return type:

namedtuple

Raises:

ValueError – If the input array is in a different format than COO.

Examples

>>> import sparse
>>> x = sparse.COO.from_numpy([1, 0, 2, 1, 2, -3])
>>> sparse.unique_counts(x)
UniqueCountsResult(values=array([-3,  0,  1,  2]), counts=array([1, 1, 2, 2]))