librosa.util.count_unique

librosa.util.count_unique(data, *, axis=-1)[source]

Count the number of unique values in a multi-dimensional array along a given axis.

Parameters:
datanp.ndarray

The input array

axisint

The target axis to count

Returns:
n_uniques

The number of unique values. This array will have one fewer dimension than the input.

See also

is_unique

Examples

>>> x = np.vander(np.arange(5))
>>> x
array([[  0,   0,   0,   0,   1],
   [  1,   1,   1,   1,   1],
   [ 16,   8,   4,   2,   1],
   [ 81,  27,   9,   3,   1],
   [256,  64,  16,   4,   1]])
>>> # Count unique values along rows (within columns)
>>> librosa.util.count_unique(x, axis=0)
array([5, 5, 5, 5, 1])
>>> # Count unique values along columns (within rows)
>>> librosa.util.count_unique(x, axis=-1)
array([2, 1, 5, 5, 5])