Согласно документации numpy, np.unique
будет возвращать уникальные значения в массиве, а также счетчики и индексы, но когда указана ось, я запутался. Может кто-нибудь объяснить пример ниже?
>>> a = np.array([[1, 2, 3], [5, 2, 3], [0, 2, 3], [1, 2, 3]])
>>> a
array([[1 2 3]
[5 2 3]
[0 2 3]
[1 2 3]])
>>> unique_rows, indices, occurrence_count = np.unique(a, axis=0, return_index=True, return_counts=True)
>>> print(unique_rows) # why not
[[[0 2 3] [1 2 3]
[1 2 3] [5 2 3]
[5 2 3]]] [0 2 3] but a strange order
>>> print(indices)
[2 0 1]
>>> print(occurrence_count)
[1 2 1]
>>> b, c, d = np.unique(a, axis = 1, return_index = True, return_counts = True)
>>> print(b)
[[1 2 3]
[5 2 3]
[0 2 3]
[1 2 3]]
>>> print(c)
[0 1 2] # where do these indices come from?
>>> print(d)
[1 1 1] # where do these counts come from?