在numpy数组中找到独特点(Finding unique points in numpy array)

编程入门 行业动态 更新时间:2024-10-17 18:24:37
在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/

更多推荐

本文发布于:2023-07-15 05:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110751.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   中找到   numpy   Finding   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!