[Numpy-discussion] bug in oldnumeric.ma

Eric Firing efiring@hawaii....
Wed May 7 13:15:59 CDT 2008

Charles Doutriaux wrote:
> The following code works with numpy.ma but not numpy.oldnumeric.ma, 

No, this is a bug in numpy.ma also; power is broken:

In [1]:import numpy as np

In [2]:x = np.ma.array([-1.1])

In [3]:x**2.0                   ### This works
masked_array(data = [1.21],
       mask = [False],

In [4]:np.ma.power(x, 2.0)     ### This doesn't
masked_array(data = [--],
       mask = [ True],

Here is the code in ma/core.py, which is masking the output for negative 

def power(a, b, third=None):
     """Computes a**b elementwise.

     Masked values are set to 1.

     if third is not None:
         raise MAError, "3-argument power not supported."
     ma = getmask(a)
     mb = getmask(b)
     m = mask_or(ma, mb)
     fa = getdata(a)
     fb = getdata(b)
     if fb.dtype.char in typecodes["Integer"]:
         return masked_array(umath.power(fa, fb), m)
     md = make_mask((fa < 0), shrink=True)              #### wrong
     m = mask_or(m, md)
     if m is nomask:
         return masked_array(umath.power(fa, fb))
         fa = fa.copy()
         fa[(fa < 0)] = 1                               #### wrong
         return masked_array(umath.power(fa, fb), m)


More information about the Numpy-discussion mailing list