How do I test if every element in a numpy array is masked? Here’s what I’d like to do:
x = #is a maksed numpy array
masked_min = numpy.ma.min(x)
if masked_min IS NOT A MASKED ELEMENT:
#do some stuff only if masked_min is a value
In practice I see this:
>>> x = numpy.ma.array(numpy.array([1,2,3]),mask=[True,True,True])
>>> masked_min = numpy.ma.min(x)
masked
Testing for masked is not helpful:
>>> numpy.ma.sum(x) == numpy.ma.masked
masked
I think the most Pythonic way would be to just do what you want, and then catch any errors that result if the entire array is masked.
For example: