Brian
Brian

Reputation: 3568

calling `numpy.where` on a `masked_array`

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! :)

Upvotes: 2

Views: 48

Answers (1)

Niemerds
Niemerds

Reputation: 942

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

print(numpy.ma.where((a <= 6))[0])

Upvotes: 3

Related Questions