[英]Find most repeated ! np.array ! in a list
I saw some solutions on finding the most common scalar in an numpy array using scipy.stats.mode / np.bincount / collections.counter.我看到了一些使用 scipy.stats.mode / np.bincount / collections.counter 在 numpy 数组中找到最常见标量的解决方案。
But I am not able to apply these on my porblem.但我无法将这些应用于我的问题。
Having an list of numpy arrays like有一个 numpy 数组列表,例如
list_name = [np.array([1,2,3]),
np.array([1,2,3]),
np.array([5,6,7]),
np.array([1,2,3]),
np.array([2,3,4]),
np.array([2,3,4])]
I would like to find the most repeated vector -> np.array([1,2,3])
in the case shown above.我想在上面显示的情况下找到重复次数最多的向量 ->
np.array([1,2,3])
。
Thanks for your help on this!感谢您对此的帮助!
Martin马丁
First convert the list of vectors to a matrix.首先将向量列表转换为矩阵。
mtx = np.matrix(list)
Get unique values with counts通过计数获取唯一值
values, counts = np.unique(mtx, return_counts=True, axis=0)
Retrieve the most common value检索最常见的值
values[counts==np.max(counts),]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.