[Numpy-discussion] Indexing a matrix with a scalar and ticket #707
Charles R Harris
charlesr.harris@gmail....
Mon Apr 28 21:02:52 CDT 2008
On Mon, Apr 28, 2008 at 7:41 PM, Charles R Harris <charlesr.harris@gmail.com>
wrote:
>
>
> On Mon, Apr 28, 2008 at 7:03 PM, Charles R Harris <
> charlesr.harris@gmail.com> wrote:
>
> > Yes, indeed.
> >
> > Ticket #707: numpy.array fails if the input is a list of matrixes (with
> > more then one column).
> >
> > The subroutine discover_dimensions in arrayobject.c indexes a matrix
> > with a scalar. It is a recursive routine and expects to find the next lower
> > dimension as it recurses down into the matrix. This works fine with matrices
> > with one column because the matrix row also has first dimension 1. Things
> > don't do so well if the matrices have more than one column. I expect this is
> > just the tip of a big pile of, um, stuff. The easy fix is to make indexing
> > by scalars the same for matrices and arrays. So I think the best thing to do
> > is provide that and figure out how to get the subarrays some other way.
> >
>
> Let me add that this settles the case of the matrix iterator for me: it
> has to return a 1D array. That behavior is part of the numpy contract that
> the core code is built on. The behavior of scalar indexing may also be part
> of that contract, but I am not sure of that.
>
In particular, if a is a matrix, then
for row in matrix:
for elem in row :
pass
has to iterate through the elements of a.
Chuck
>
> Chuck
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080428/993ba33d/attachment.html
More information about the Numpy-discussion
mailing list