📅  最后修改于: 2022-03-11 14:48:28.756000             🧑  作者: Mango
mat5 = np.array([['a', 'g', 'c'],
['a', 'b', 'c'],
['f', 'c', 'c']])
val, cnts = np.unique(mat5, return_counts=True)
dict_unique = {k: v for k, v in zip(val, cnts)}
""" result: {'a': 2, 'b': 1, 'c': 4, 'f': 1, 'g': 1} """