jlt199
jlt199

Reputation: 2449

Python - Coordinates of an array

I'm sorry, I think this is a really trivial question, but...

I have a binary Numpy array, mostly zeros with a few ones. I would like to find the coordinates of all the locations where myArray[myArray == 1]

Please can you help me? Thanks

Upvotes: 1

Views: 88

Answers (2)

Elsa Gonsiorowski
Elsa Gonsiorowski

Reputation: 101

If you are using a list (rather than a numpy array), this answer uses enumerate in both a loop and list comprehension: https://stackoverflow.com/a/17202481/1160876

Upvotes: 0

Joran Beasley
Joran Beasley

Reputation: 114108

np.where(myArray==1)

I guess, should work (assuming its numpy array, based on your indexing example)

Upvotes: 2

Related Questions