ma.masked_array.__eq__
is actually implemented in numpy, but maybe it does not have the semantics you are looking for? You can get to the documentation with help(ma.masked_array.__eq__)
with a python interpreter, it states:
Check whether other equals self elementwise
Which is what I can see given your example: it does the comparison where the data is marked as valid, and returns the result in the data field of a masked array. Wherever the data was invalid (for a or b) the resulting masked array field is masked.
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = ma.masked_array([0,1,2,3],[True,False,False,False])
>>> b = ma.masked_array([0,1,2,3],[True,True,False,False])
>>> a==b
masked_array(data = [-- -- True True],
mask = [ True True False False],
fill_value = True)
>>> b = ma.masked_array([0,1,2,4],[True,True,False,False])
>>> a==b
masked_array(data = [-- -- True False],
mask = [ True True False False],
fill_value = True)
If you want to check that all the fields are valid and equal you could use:
np.allfalse((a==b).data)
edit: actually, I think you would need:
not np.any((a==b).mask) and np.alltrue((a==b).compressed())
If you want to check that all the valid fields are equal you could use:
np.alltrue((a==b).compressed())
As user2357112 explained in the comment, numpy.testing
provides functions for unit testing on numpy arrays, which might not be what you are looking for. It it is, you could still use the regular assert
function with the examples that I provided.