[Numpy-discussion] untenable matrix behavior in SVN

Travis E. Oliphant oliphant at enthought.com
Sat Apr 26 14:52:25 EDT 2008


Alan G Isaac wrote:
> On Sat, 26 Apr 2008, Gael Varoquaux apparently wrote:
>   
>> For me this is wrong. list and tuples are not 2D. Numpy 
>> arrays happen to offer this feature, but you should not 
>> use it do to multiple dimension indexing. 
>>     
>
> But there is no proposal that people should index like this.
> The underlying issue is iteration.  Currently::
>
>     >>> A
>     matrix([[1,  2],
>             [ 3,  4]])
>     >>> A = np.mat(x)
>     >>> for row in A:
>     ...  for col in row:
>     ...   print col
>     ...
>     [[1  2]]
>     [[3 4]]
>
> So are you saying that one should not be able to iterate 
> through to the elements of a matrix?
>   

Iteration can be handled separately with __iter__ method that returns 
the actual iterator object which may be different.   Or, as others have 
proposed .rows and .cols iterators.

I'm not personally persuaded by the iteration argument, because we can 
change iteration independently of mapping (__getitem__) access.

-Travis




More information about the NumPy-Discussion mailing list