[Numpy-discussion] untenable matrix behavior in SVN
Tue Apr 29 17:52:27 CDT 2008
On 30/04/2008, Keith Goodman <firstname.lastname@example.org> wrote:
> On Tue, Apr 29, 2008 at 2:18 PM, Anne Archibald
> <email@example.com> wrote:
> > It is actually pretty unreasonable to hope that
> > A
> > and
> > A[[1,2,3]]
> > or
> > A[[True,False,True]]
> > should return objects of the same rank.
> Why it unreasonable to hope that
> x[0, [1,2,3]]
> x[0, [True,False,True]]
> where x is a matrix, continue to return matrices?
Well, I will point out that your example is somewhat different from
mine; nobody is arguing that your three examples should return objects
of different ranks. There is some disagreement over whether
should be a rank-1 or a rank-2 object, but x[0,[1,2,3]] and x[0,
[True, False, True]] should all have the same rank as x[0,:]. Nobody's
What I was pointing out is that x[0,0] should not have the same rank
as x[0,:] or x[0,]. In this case it's obvious; x[0,0] should be a
scalar. But the same logic applies to
For arrays, if x has rank 2, x[0,:] has rank 1. if L is a list of
indices, x[L,:] always has rank 2, no matter what is actually in L
(even if it's one element). It is perfectly reasonable that they
should yield objects of different ranks.
With matrices, we have the surprising result that x[0,:] is still a
two-dimensional object; to get at its third element I have to specify
x[0,:][0,2]. It seems to me that this is a peculiar hack designed to
ensure that the result still has "*" defined in a matrix way.
More information about the Numpy-discussion