[Numpy-discussion] matrix-related bug in 1.0b1
wbaxter at gmail.com
Sun Jul 23 20:58:43 CDT 2006
On 7/22/06, Sven Schreiber <svetosch at gmx.net> wrote:
> Summary: Slicing seems to be broken with matrices now.
> >>> import numpy as n
> >>> n.__version__
> >>> import numpy.matlib as m
> >>> a = n.zeros((2,3))
> >>> b = m.zeros((2,3))
> >>> a[:1,:].shape
> (1, 3)
> >>> b[:1,:].shape
> (3, 1)
> Note the array slicing works correct, but the equivalent thing with the
> matrix does not.
Looks like it happened in rev 2698 of defmatrix.py, matrix.__getitem__ method:
retscal = True
elif out.shape == 1:
sh = out.shape
out.shape = (sh, sh)
==> elif isinstance(index, (slice, types.EllipsisType)):
==> if out.shape == 1 and not isscalar(index):
It behaves like array if you remove the 'not' in the last line.
But maybe that breaks some other cases?
Maybe you can try making that change in your numpy/core/defmatrix.py
(around line 140) and see if anything else breaks for you.
> I also noticed the following (in a new python session) import strangeness:
> >>> import numpy
> >>> numpy.matlib.zeros((2,3))
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> AttributeError: 'module' object has no attribute 'matlib'
> Why is the direct access to matlib impossible?
Maybe the thinking is that since it's a compatibily module, if you
want it you should explicity import it. Like you have to do with
More information about the Numpy-discussion