[Numpy-discussion] numpy.matrix subclassing

David Voong voong.david at gmail.com
Mon Oct 24 18:54:33 EDT 2011


Hi guys,

I have a question regarding subclassing of the numpy.matrix class.

I read through the wiki page,
http://docs.scipy.org/doc/numpy/user/basics.subclassing.html

and tried to subclass numpy.matrix, I find that if I override the
__finalize_array__ method I have problems using the sum method and get the
following error,


Traceback (most recent call last):
  File "test.py", line 61, in <module>
    print (a * b).sum()
  File "/afs/
cern.ch/user/d/dvoong/programs/lib/python2.6/site-packages/numpy/matrixlib/defmatrix.py",
line 435, in sum
    return N.ndarray.sum(self, axis, dtype, out)._align(axis)
  File "/afs/
cern.ch/user/d/dvoong/programs/lib/python2.6/site-packages/numpy/matrixlib/defmatrix.py",
line 370, in _align
    return self[0,0]
  File "/afs/
cern.ch/user/d/dvoong/programs/lib/python2.6/site-packages/numpy/matrixlib/defmatrix.py",
line 305, in __getitem__
    out = N.ndarray.__getitem__(self, index)
IndexError: 0-d arrays can only use a single () or a list of newaxes (and a
single ...) as an index

Can anyone help?

It's my first time on this mailing list so apologies if this is not the
right place to discuss this.

Regards

David Voong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111025/cd571d24/attachment.html>


More information about the NumPy-Discussion mailing list