[Numpy-discussion] matrix vs. array

Colin J. Williams cjw at sympatico.ca
Wed Mar 15 04:51:03 EST 2006


Bill Baxter wrote:

>
> On 3/15/06, *Paulo J. S. Silva* <pjssilva at ime.usp.br 
> <mailto: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.

A true matrix has two dimensions.  The example above would appear to be 
a bug.

Colin W.

>
> --bb






More information about the NumPy-Discussion mailing list