改进np.unique,使其返回的值不是自动排序
import numpy as np
def np_unranked_unique(nparray):
n_unique = len(np.unique(nparray))
ranked_unique = np.zeros([n_unique])
i = 0
for x in nparray:
if x not in ranked_unique:
ranked_unique[i] = x
i += 1
return ranked_unique
arr = np.array([2, 3, 3, 1, 2])
print(np.unique(arr), np_unranked_unique(arr))
output: [1 2 3] [2. 3. 1.]