[Numpy-discussion] matrix indexing question

Alan G Isaac aisaac@american....
Mon Mar 26 08:31:06 CDT 2007

> Alan G Isaac schrieb: 
>>     >>> X[1] 
>>     array([3,4]) 
>>     >>> X[1,:] 
>>     matrix([[3, 4]]) 

>> But again the point is: 
>> indexing for submatrices should produce matrices. 
>> Normal Python indexing should access the constituent arrays. 

On Mon, 26 Mar 2007, Sven Schreiber apparently wrote: 
> I think this is a tricky business. 
> There's also the rule "indexing reduces the rank, slicing preserves it". 
> Numpy-matrices form an exception to this rule, always being 2d, but the 
> exception is consistently enforced. 
> Now it seems you want to have an exception from the exception, correct? 

What I want: the best design.
I did not claim that the current design is flawed, only to suspect it.

Why I wrote: current behavior feels wrong -> suspect design flaw.

What feels wrong: iterating over a container does not give 
access to the contained objects.  This is not Pythonic.

*Symptom* of the underlying problem:
for matrix M, M[0] returns a matrix.

Would the change I suggest mean that the behavior of the 
matrix class deviates less from the array class: yes.

Does this mean the matrix class behavior would be less "consistent"?
I have tried to explain why the answer is "no".

Alan Isaac

More information about the Numpy-discussion mailing list