[Numpy-discussion] sum of a masked array

smpitts at ou.edu smpitts at ou.edu
Wed Sep 1 13:21:10 EDT 2004


Darren,
I tried your code on my system: Python 2.2 and numarray 1.0. The type error looks like a bug in the array display code.

>>> Rx = ones((2500,2500))
>>> N = make_mask_none((2500,2500))
>>> Rx = array(Rx,mask=N)
>>> print average(Rx) ## works
[ 1.  1.  1. ...,  1.  1.  1.]
>>> s = sum(Rx)
>>> print s

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/site-packages/numarray/ma/MA.py", line 742, in __str__
    return str(filled(self, f))
  File "/usr/lib/python2.2/site-packages/numarray/generic.py", line 499, in __str__
    return arrayprint.array2string(self, separator=" ", style=str)
  File "/usr/lib/python2.2/site-packages/numarray/arrayprint.py", line 188, in array2string
    separator, prefix)
  File "/usr/lib/python2.2/site-packages/numarray/arrayprint.py", line 137, in _array2string
    data = _leading_trailing(a)
  File "/usr/lib/python2.2/site-packages/numarray/arrayprint.py", line 105, in _leading_trailing
    b = _gen.concatenate((a[:_summaryEdgeItems],
  File "/usr/lib/python2.2/site-packages/numarray/generic.py", line 1028, in concatenate
    return _concat(arrs)
  File "/usr/lib/python2.2/site-packages/numarray/generic.py", line 1012, in _concat
    dest  = arrs[0].__class__(shape=destShape, type=convType)
TypeError: __init__() got an unexpected keyword argument 'type'

but the array is fine

>>> for i in range(2500): 
...     assert s[i] == 2500
>>> 

Hopefully someone with more knowledge can help you out. I still use MA with Numeric for the most part.
--
Stephen Pitts
smpitts at ou.edu





More information about the NumPy-Discussion mailing list