[Numpy-discussion] untenable matrix behavior in SVN
Charles R Harris
Tue Apr 29 09:01:13 CDT 2008
On Tue, Apr 29, 2008 at 7:24 AM, Stéfan van der Walt <email@example.com>
> Hi Charles
> 2008/4/29 Charles R Harris <firstname.lastname@example.org>:
> > May I add that if I edit defmatrix.py to act like an array for scalar
> > indexing, then the following works.
> > In : a = matrix(eye(2))
> > In : array([a,a])
> > Out:
> > array([[[ 1., 0.],
> > [ 0., 1.]],
> > [[ 1., 0.],
> > [ 0., 1.]]])
> > This generates an error with the current version of matrix and, frankly,
> > am not going to be bothered going all through the numpy c sources to
> > case matrices to fix that. Someone else can do it if they wish. There
> > recursive routines that expect the dimensions to decrease on each call.
> I'd also like to see matrices become proper hierarchical containers --
> the question is just how to do that. Thus far, I'm most convinced by
> the arguments for RowVectors/Columns, which leaves us with a sane
> model for doing linear algebra, while providing the enhancements you
> mentioned here and in comments to another ticket.
> We were thinking of raising a warning on scalar indexing for 1.1, but
> given the above, would that be sensical?
The numpy c routines call PySequence_GetItem(s,i) as well as ask for the
length (first index), so I think these should be left as they are for arrays
in order to guarantee that matrices are compatible with all the normal array
operations. This means either returning special row objects that index as
expected, or returning 1D arrays. I don't think the '*' operator has these
problems, but in any case that is a well documented feature of matrices.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion