import numpy as np
def getUniqueNumber(x):
n = len(x)
unique_x = np.unique(x)
g = len(unique_x)
tp = np.zeros(unique_x.shape)
demo = np.ones(n)
for i in range(g):
tp[i] = np.sum(demo[x == unique_x[i]])
return unique_x, tp
data = [1, 2, 3, 4, 5, 6, 7, 2]
u_data, tp = getUniqueNumber(data)
print(u_data,tp)
【Python】计算数组重复个数
于 2022-01-25 03:47:16 首次发布