[Numpy-discussion] matrix indexing question
Alan G Isaac
Sun Mar 25 21:26:24 CDT 2007
>> On 3/26/07, Alan G Isaac <firstname.lastname@example.org> wrote:
>>> finds itself in basic conflict with the idea that
>>> I ought to be able to iterate over the objects in an
>>> iterable container. I mean really, does this not "feel"
>>> wrong? ::
>>> for item in x: print item.__repr__()
>>> matrix([[1, 2]])
>>> matrix([[3, 4]])
On Mon, 26 Mar 2007, Bill Baxter apparently wrote:
> So you're saying this is what you'd find more pythonic?
> Just trying to make it clear what you're proposing.
No; that is not possible, since a matrix is inherently 2d.
I just want to get the constituent arrays when I iterate
over the matrix object or use regular Python indexing, but
a matrix when I use matrix/array indexing. That is ::
That behavior seems completely natural and unsurprising.
> Probably about half the bugs I get from mixing and matching matrix and
> array are things like
> row = A[i]
> z = row
> Which works for an array but not for a matrix.
That is the evidence of a "bad surprise" in the current
behavior. Iterating over a Python iterable should provide
access to the contained objects.
More information about the Numpy-discussion