[Numpy-discussion] matrix indexing question

Travis Oliphant oliphant@ee.byu....
Mon Mar 26 15:30:17 CDT 2007


Alan G Isaac wrote:

>>>On Mon, 26 Mar 2007, "Colin J. Williams" apparently wrote: 
>>>      
>>>
>>>>One would expect the iteration over A to return row 
>>>>vectors, represented by (1, n) matrices. 
>>>>        
>>>>
>
>
>  
>
>>On 3/26/07, Alan G Isaac <aisaac@american.edu> wrote: 
>>    
>>
>>>This is again simple assertion. 
>>>**Why** would "one" expect this? 
>>>Some people clearly do not. 
>>>      
>>>
>
>
>On Mon, 26 Mar 2007, Charles R Harris apparently wrote: 
>  
>
>>Well, and what should they expect.
>>    
>>
>
>
>Since matrices are an iterable Python object,
>we *expect* to iterate over the contained objects.
>(Arrays.)  I am not sure why this is not evident to all,
>but it is surely the sticking point in this discussion.
>
>A matrix is not a container of matrices.
>That it acts like one is surprsing.
>Surprises are bad unless they have a clear justification.
>Perhaps a clear justification exists,
>but it has not been offered in this discussion.
>  
>

It actually has been offered.   You just don't accept it. 

Matrices are containers of matrices.  

If M is an (mxn) matrix then M[0] is a (1xn) matrix. 

Viewing this 1xn matrix as a 1-d array loses it's row-vectorness. 

This seems perfectly logical and acceptable to me.  I'm waiting for a 
better explanation as to why this is not acceptable.

Arguments that rest on what is and what isn't "Pythonic" are not very 
persuasive as this is very often in the eye of the beholder.

-Travis



More information about the Numpy-discussion mailing list