2

Here's an example:

import numpy
from numpy import arange, where
from numpy.ma import masked_array

a = masked_array(arange(10), arange(10) < 5)
print(where((a <= 6))[0])

Expected output:

[5, 6]

Actual output:

[0, 1, 2, 3, 4, 5, 6]

How can I achieve the expected output? Thanks! :)

Brian
  • 3,453
  • 2
  • 27
  • 39

1 Answers1

3

You simply need to use "numpy.ma.where" in order to handle the masked array:

print(numpy.ma.where((a <= 6))[0])
Niemerds
  • 932
  • 7
  • 12
  • Oh okay--Thanks! Before I read the docs, I was thinking maybe `masked_where` was the answer. I searched "where" on what I thought was the `numpy.ma` docs page and didn't see anything other than `masked_where`. – Brian Mar 25 '16 at 09:41