1

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

jlt199
  • 1,919
  • 6
  • 20
  • 38

2 Answers2

2
np.where(myArray==1)

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

Joran Beasley
  • 103,130
  • 11
  • 146
  • 174
0

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

Community
  • 1
  • 1