[Numpy-discussion] untenable matrix behavior in SVN
Alan G Isaac
aisaac@american....
Sat Apr 26 10:13:12 CDT 2008
On Sat, 26 Apr 2008, Gael Varoquaux apparently wrote:
> I claim b is more important than a. IMHO, a is plain
> wrong: you should't be indexing x with x[0][0].
Why?? Would you say this about a 2d array?
Why the difference?
The core argument has been that it is a **basic
expectation** of the behavior of 2d array-like objects that
you will be able to get, e.g., the first element with x[0][0].
(E.g., lists, tuples, arrays ... is there an exception??
It should not be broken!)
I teach with matrices and I thought you might too: if so,
you surely have run into this expectation (which is **natural**).
In fact I truly doubt anyone has not been puzzled on first
encounter by this::
>>> x
matrix([[1, 2],
[3, 4]])
>>> x[0]
matrix([[1, 2]])
>>> x[0][0]
matrix([[1, 2]])
Another argument, which I agree with, has been that matrix
behavior should match 2d array behavior except where there
is a clear payoff from deviation.
What I do agree with, which I take to be implicit in your
statement, is that if users of matrices should generally use
multiple indexes. But that does not answer the question
about what we should offer when x[0] is requested.
(Or, more crucially, what you get when you iterate over
a matrix.)
Cheers,
Alan Isaac
PS If you have good arguments, please add them to
<URL:http://www.scipy.org/MatrixIndexing>
More information about the Numpy-discussion
mailing list