[Numpy-discussion] [SciPy-user] maskedarray
Alan G Isaac
Wed Dec 12 21:27:48 CST 2007
On Wed, 12 Dec 2007, "Travis E. Oliphant" apparently wrote:
> 2) The matrix object made a C-subclass (for speed).
This will probably be the last chance for such a change,
so I again hope that consideration will be given to *one*
change in the matrix object:
iteration over a matrix should return arrays
(instead of matrices).
So if A is a matrix,
A should be an array,
but A[1,:] should be a matrix.
Obviously this is an argument from design rather
than from functionality. Current behavior is not "natural".
E.g., it makes it awkward to iterate over all elements in
the "natural" way, which I claim is::
for row in A:
for element in row:
This example is just meant to illustrate in a simple way
what is "odd" about the current behavior. (It is not meant
to be an "argument" nor to suggest that the current absence
simple ways to do the same thing---e.g., using A.A.)
Whenever I am working with matrices, I notice some aspect of
this "oddity", and it is annoying when so much else is quite
PS For those who do not know, here is an example of the
current behavior. (The following prints 2 matrices instead
of 4 elements.)
>>> A = N.mat('1 2;3 4')
>>> for row in A:
... for element in row:
... print element
More information about the Numpy-discussion