[SciPy-user] change in matrix behavior

Alan G Isaac aisaac@american....
Thu May 8 13:51:08 CDT 2008

On Thu, 8 May 2008, Nathan Bell apparently wrote:
> there are no rank 1 implementations of the 
> matrices in scipy.sparse, so it was more natural for A[1] to return a 
> 2d matrix.  Furthermore, we now have the odd situation where indexing 
> a matrix now returns a different type. 

These issues were extensively discussed on the NumPy list.
I hope you will read that discussion.

> Oh, and iterating over the rows of a matrix works differently now, e.g. 
> from numpy import * 
> A = asmatrix(arange(9).reshape(3,3))
> for row in A:
>     print row.shape
> row.shape is now (3,) rather than (1,3)

After *extensive* discussion, most people felt that this is 
a good thing. Among those who did not agree or were not 
sure, raising an error in response to scalar indexing was 
popular.  Otherwise, every function that iterates through 
arrays and expects dimensional reduction as it does so must 
special case matrices.  This was seen as untenable.

Query: How do you use iteration over a matrix?

> Oh, and these non-backwards compatible changes were made 
> on a minor version release.

I submitted a patch that would have issued a warning about 
scalar indexing rather than change the behavior immediately.
However, as a user, I believe this change is both good and 
necessary.  I do not have an opinion on the timing, as long 
as the change really takes place.  My impression of the 
discussion was that 1.1 was being considered as almost the 
last opportunity for API changes ...

Query: can you specify what needed behavior appears to have 
broken because of this change?

Alan Isaac

More information about the SciPy-user mailing list