Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading