import numpy as np a = [1,2,3,45,6,7,123,2,1,3,4,5,123,2,3,4] def all_np(arr): arr = np.array(arr) key = np.unique(arr) result = {} for k in key: mask = (arr == k) arr_new = arr[mask] v = arr_new.size result[k] = v return result ret = all_np(a) print(ret) # 结果 # {1: 2, 2: 3, 3: 3, 4: 2, 5: 1, 6: 1, 7: 1, 45: 1, 123: 2}