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
  • 2,349
  • 6
  • 23
  • 43

2 Answers2

2
np.where(myArray==1)

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

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
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