[Numpy-discussion] matrix-related bug in 1.0b1

Bill Baxter wbaxter at gmail.com
Sun Jul 23 20:58:43 CDT 2006


Howdy,

On 7/22/06, Sven Schreiber <svetosch at gmx.net> wrote:
> Hi,
>
> Summary: Slicing seems to be broken with matrices now.
>
> ...
> Example:
>
> >>> import numpy as n
> >>> n.__version__
> '1.0b1'
> >>> 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:

                if isscalar(index[1]):
                    if isscalar(index[0]):
                        retscal = True
                    elif out.shape[0] == 1:
                        sh = out.shape
                        out.shape = (sh[1], sh[0])
            ==> elif isinstance(index[1], (slice, types.EllipsisType)):
            ==>     if out.shape[0] == 1 and not isscalar(index[0]):

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
oldnumeric.

--bb




More information about the Numpy-discussion mailing list