计算数组中数组的出现次数[重复]

问题描述 投票:0回答:1

嗨,我有一个像这样的二维数组

[[0 2]
 [0 1]
 [1 2]
 [1 2]
 [0 1]
 [1 2]
 [0 1]
 [0 1]
 [1 3]
 [2 3]]

我需要计算每个数组的出现次数,例如 [0, 1] = 4、[0,2] = 1 等。最好使用 numpy。 然后提取最大值。 预先感谢。

python numpy counting
1个回答
0
投票

np.unique() 会为你做的

unique_arr, num = np.unique(arr, axis=0, return_counts=True)
© www.soinside.com 2019 - 2024. All rights reserved.