热线电话:13121318867

登录
2019-01-23 阅读量: 732
计算多维numpy数组中的副本

我正在使用python-3.x,我想计算numpy数组中的重复数....例如:

import numpy as np

my_array = np.array([[2, 3, 5],

[2, 3, 5], # duplicate of row 0 (this will be count as 1)

[2, 3, 5], # duplicate of row 0 (this will be count as 2)

[1, 0, 9],

[3, 6, 6],

[3, 6, 6], # duplicate of row 0 (this will be count as 3)

[1, 0, 9]])

我想从outptu得到的是这个数组中的重复数量:

the number of the duplicate is 3

大多数方法都返回诸如collections.Counter或return_counts之类的值。

#####################

想到的解决方法是:可以通过获取数组的长度来获取数组的重复计数 - 数组的唯一成员的长度:

the_number_of the duplicate = len(my_array) - len(np.unique(my_array, axis=0))

0.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子