Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 计算多维numpy数组中的副本_Python 3.x_Numpy_Multidimensional Array_Duplicates - Fatal编程技术网

Python 3.x 计算多维numpy数组中的副本

Python 3.x 计算多维numpy数组中的副本,python-3.x,numpy,multidimensional-array,duplicates,Python 3.x,Numpy,Multidimensional Array,Duplicates,我使用的是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)

我使用的是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\u counts,如果我正确使用它们,它们不会返回我想要的值


任何建议都将不胜感激

您可以通过获取数组长度-数组唯一成员的长度来获取数组的重复计数:

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

你的例子的结果是4([1,0,9]也是重复的)。

这里与@Anh Ngoc的答案略有不同。(对于较早版本的numpy,
np.unique
不支持
axis


非常感谢,我不认为这会像你的回答那么简单:)非常感谢你的建议:)
number_of_duplicates = len(my_array) - len(set(map(tuple, my_array)))