Home > Blockchain >  What is the best way to find y coordinates of point with specified x value in numpy array
What is the best way to find y coordinates of point with specified x value in numpy array

Time:04-27

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?

CodePudding user response:

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])
  • Related