[Numpy-discussion] proposing a "beware of [as]matrix()" warning

David Warde-Farley dwf at cs.toronto.edu
Mon Apr 26 20:19:25 EDT 2010


Trying to debug code written by an undergrad working for a colleague of 
mine who ported code over from MATLAB, I am seeing an ugly melange of 
matrix objects and ndarrays that are interacting poorly with each other 
and various functions in SciPy/other libraries. In particular there was 
a custom minimizer function that contained a line "a * b", that was 
receiving an Nx1 "matrix" and a N-length array and computing an outer 
product. Hence the unexpected 6 GB of memory usage and weird results...

We've had this discussion before and it seems that the matrix class 
isn't going anywhere (I *really* wish it would at least be banished from 
the top-level namespace), but it has its adherents for pedagogical 
reasons. Could we at least consider putting a gigantic warning on all 
the functions for creating matrix objects (matrix, mat, asmatrix, etc.) 
that they may not behave quite so predictably in some situations and 
should be avoided when writing nontrivial code?

There are already such warnings scattered about on SciPy.org but the 
situation is so bad, in my opinion (bad from a programming perspective 
and bad from a new user perspective, asking "why doesn't this work? why 
doesn't that work? why is this language/library/etc. so stupid, 
inconsistent, etc.?") that the situation warrants steering people still 
further away from the matrix object.

I apologize for ranting, but it pains me when people give up on 
Python/NumPy because they can't figure out inconsistencies that aren't 
really there for a good reason. IMHO, of course.

David

David



More information about the NumPy-Discussion mailing list