我需要找到一个独特的行numpy.array.
例如:
>>> a # I have
array([[1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 0, 0],
[1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 1, 0]])
>>> new_a # I want to get to
array([[1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 0]])
Run Code Online (Sandbox Code Playgroud)
我知道我可以在阵列上创建一个集合并循环,但我正在寻找一个有效的纯numpy解决方案.我相信有一种方法可以将数据类型设置为void然后我可以使用numpy.unique,但我无法弄清楚如何使其工作.
如何删除二维numpy数组的重复行?
data = np.array([[1,8,3,3,4],
[1,8,9,9,4],
[1,8,3,3,4]])
Run Code Online (Sandbox Code Playgroud)
答案应如下:
ans = array([[1,8,3,3,4],
[1,8,9,9,4]])
Run Code Online (Sandbox Code Playgroud)
如果有两行相同,那么我想删除一个"重复"行.
什么是在numpy数组中找到唯一x,y点(删除重复项)的更快方法,如:
points = numpy.random.randint(0, 5, (10,2))
Run Code Online (Sandbox Code Playgroud)
我想过将点转换为复数然后检查唯一,但这似乎相当复杂:
b = numpy.unique(points[:,0] + 1j * points[:,1])
points = numpy.column_stack((b.real, b.imag))
Run Code Online (Sandbox Code Playgroud) 我有一个形状数组,(128, 36, 8)我想找到最后一个维度中长度为8的唯一子数组的出现次数.
我知道np.unique并且np.bincount,但那些似乎是元素而不是子阵列.我已经看到了这个问题,但它是关于找到特定子阵列的第一次出现,而不是所有独特子阵列的计数.
我想知道在两组轮廓线之间找到所有交点(到舍入误差)的最佳方法.这是最好的方法吗?这是一个例子:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,500)
X,Y = np.meshgrid(x,x)
Z1 = np.abs(np.sin(2*X**2+Y))
Z2 = np.abs(np.cos(2*Y**2+X**2))
plt.contour(Z1,colors='k')
plt.contour(Z2,colors='r')
plt.show()
Run Code Online (Sandbox Code Playgroud)

我想要一些类似的:
intersection_points = intersect(contour1,contour2)
print intersection_points
[(x1,y1),...,(xn,yn)]
Run Code Online (Sandbox Code Playgroud)