'What is the best way to find y coordinates of point with specified x value in numpy array
I am, usinf python an numpy array. I want to find all y coordinates of point with specified x coordinate. I use this:
[it[1] for it in arrP if it[0] == specX]
is there better way?
Solution 1:[1]
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]
Outputs
array([2, 3])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tyson.wu |
