[Numpy-discussion] numpy release
Alan G Isaac
aisaac@american....
Thu Apr 24 15:24:26 CDT 2008
On Thu, 24 Apr 2008, Christopher Barker apparently wrote:
> for r in MyMatrix.A:
Of course: this possibility is mentioned explicitly in
several of my posts. There are a few different answers to
why asking users to do this annoying:
1. It is a deviation from the behavior of 2d arrays
that does not seem to "buy" anything, so it
pointlessly breaks a natural expectation. (But
maybe some will show that it does buy a benefit.)
So it breaks the rule: stick with the behavior of 2d
arrays except for *, **, and nonscalar indexing,
which is a pretty understandable rule. To this
extent I agree with Tim that matrices and arrays
should be as alike as it is feasible to make them,
while still getting the convenience of *, **, and
submatrices via nonscalar indexing.
2. Whenever you do not know ahead of time whether
you will pass an array or a matrix, you must bear
the (small but annoying) cost of working around your
ignorance.
3. In my own experience, whenever I want to iterate
over a matrix, I want the 1d arrays. Others may
have different experiences, but they have not shared
them. Unless we find users who actually want the
vectors you want to provide them with, you seem to
be promoting this approach based on fairly abstract
design considerations. (Which is not necessarily
bad of course.)
4. If users do want to iterate over rows and
columns, it is more natural (i.e., symmetrical) to
provide these as attributes of the matrix.
I do not mean for any of this to be determinative. Indeed,
against this are two possible arguments.
1. For matrices and sparse matrices to nicely behave
alike, your proposal will be necessary. (This case
has not been made yet, however.)
2. I think Stefan might argue something like, to
leave the "linear algebra world", you should have to
be quite explicit, as x.A is. I find it explict
enough if we use a matrix as an iterator---to me
that means indeed I am leaving the matrices in favor
of arrays.
Cheers,
Alan Isaac
More information about the Numpy-discussion
mailing list