在numpy数组中找到独特点(Finding unique points in numpy array)
在numpy数组中找到唯一的x,y点(删除重复项)的更快方法是:
points = numpy.random.randint(0, 5, (10,2))我想将点转换为复数,然后检查独特的,但这似乎相当复杂:
b = numpy.unique(points[:,0] + 1j * points[:,1]) points = numpy.column_stack((b.real, b.imag))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-remove-duplicates-from-a-sequence/
I would do it like this:
numpy.array(list(set(tuple(p) for p in points)))
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/
更多推荐
发布评论