在numpy数组中查找指定x值的点的y坐标的最佳方法是什么?



我是,使用python numpy数组。我想求出指定x坐标的点的所有y坐标。我用这个:

[it[1] for it in arrP if it[0] == specX]

有更好的方法吗?

arr = np.array([[1,2],[1,3],[2,3]])
# select x in arr with x[0] == 1, and slice out x[1]
arr[arr[:, 0] == 1][:, 1]

输出
array([2, 3])

最新更新