1number_list = numpy.array([1, 1, 2, 3, 4, 4, 1])
2(unique, counts) = numpy.unique(number_list, return_counts=True)
1>>> a = np.array(['a', 'b', 'b', 'c', 'a'])
2>>> u, indices = np.unique(a, return_index=True)
3>>> u
4array(['a', 'b', 'c'], dtype='<U1')
5>>> indices
6array([0, 1, 3])
7>>> a[indices]
8array(['a', 'b', 'c'], dtype='<U1')
9
1>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
2>>> values, counts = np.unique(a, return_counts=True)
3>>> values
4array([1, 2, 3, 4, 6])
5>>> counts
6array([1, 3, 1, 1, 1])
7>>> np.repeat(values, counts)
8array([1, 2, 2, 2, 3, 4, 6]) # original order not preserved
9
1>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
2>>> u, indices = np.unique(a, return_inverse=True)
3>>> u
4array([1, 2, 3, 4, 6])
5>>> indices
6array([0, 1, 4, 3, 1, 2, 1])
7>>> u[indices]
8array([1, 2, 6, 4, 2, 3, 2])
9
1>>> a = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]])
2>>> np.unique(a, axis=0)
3array([[1, 0, 0], [2, 3, 4]])
4
1>>> np.unique([1, 1, 2, 2, 3, 3])
2array([1, 2, 3])
3>>> a = np.array([[1, 1], [2, 3]])
4>>> np.unique(a)
5array([1, 2, 3])
6