在numpy数组中查找唯一点 [英] Finding unique points in numpy array
本文介绍了在numpy数组中查找唯一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在numpy数组中查找唯一的x,y点(删除重复项)的更快方法是什么:
What is a faster way of finding unique x,y points (removing duplicates) in a numpy array like:
points = numpy.random.randint(0, 5, (10,2))
我想到了将点转换为复数,然后检查唯一性的方法,但这似乎有些令人费解:
I thought of converting points to a complex numbers and then checking for unique, but that seems rather convoluted:
b = numpy.unique(points[:,0] + 1j * points[:,1])
points = numpy.column_stack((b.real, b.imag))
推荐答案
我会这样:
numpy.array(list(set(tuple(p) for p in points)))
对于大多数情况下的快速解决方案,也许此菜谱会让您感兴趣: http://code.activestate.com/recipes/52560-从序列中删除重复项/
For the fast solution in the most general case, maybe this recipe would interest you: http://code.activestate.com/recipes/52560-remove-duplicates-from-a-sequence/
这篇关于在numpy数组中查找唯一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文