[Numpy-discussion] matrix vs. array

Bill Baxter wbaxter at gmail.com
Wed Mar 15 03:40:01 EST 2006


On 3/15/06, Paulo J. S. Silva <pjssilva at ime.usp.br> wrote:
>
>
> > The other difference which isn't really obvious from looking at the
> > source code is that matrices always have at least rank
>
> Just to make clear. They *always* have rank two.


Not necessarily.

>>> m = numpy.matrix('[1 2 3; 4 5 6]')
>>> mm = m[numpy.matrix('[0 1]')]
>>> m
matrix([[1, 2, 3],
       [4, 5, 6]])
>>> mm
matrix([[[[1, 2, 3]],

        [[4, 5, 6]]]])
>>> mm.shape
(1, 2, 1, 3)

Maybe that's not supposed to be possible, but with current numpy (well,
0.9.5 at least) you see it is possible to get something with type matrix
that is not rank 2.

--bb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060315/8b7faac6/attachment.html>


More information about the NumPy-Discussion mailing list