[Numpy-discussion] matrix indexing question
Bill Baxter
wbaxter@gmail....
Sun Mar 25 20:49:40 CDT 2007
On 3/26/07, Alan G Isaac <aisaac@american.edu> wrote:
> > On 3/26/07, Alan G Isaac <aisaac@american.edu> 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:
> > This may sound silly, but I really think seeing all those
> > brackets is what makes it feel wrong.
>
>
> I appreciate the agreement that it feels wrong, but
> I dispute the analysis of this symptom. What makes it "feel
> wrong", I contend, is that experience with Python make this
> a **surprising** behavior. And that is precisely why
> I suggest that this may point to a design issue.
So you're saying this is what you'd find more pythonic?
>>> X[1]
matrix([2,3])
>>> X[:,1]
matrix([[3,
4]])
Just trying to make it clear what you're proposing.
Probably about half the bugs I get from mixing and matching matrix and
array are things like
row = A[i]
...
z = row[2]
Which works for an array but not for a matrix.
I think Matlab makes it more bearable by having a single value index
like X[i] be equivalent to X.flat()[i]. So X[2] is the same for row
or col vec in Matlab. Now that I think about it, that's probably the
main reason I feel more comfortable with array than matrix in Numpy.
If I have a vector, I should only need one index to get the ith
component.
--bb
More information about the Numpy-discussion
mailing list