# [Numpy-discussion] Release of NumPy

Alan G Isaac aisaac@american....
Wed Apr 16 18:52:47 CDT 2008

```On Thu, 17 Apr 2008, Gael Varoquaux apparently wrote:
> I am sorry, I don't see why you prioritize "x[i][j] == x[i,j]" (1) more than
> "x[0] == x[0,:]" (2).

use matrices for awhile,
and I expect you will see why,
and teach them for awhile, and
I am quite sure you will see why.

But to provide some explanation.
The underlying issue is not quite whether ``x[i][j] == x[i,j]``,
but whether ``x[i][j]`` accesses the i,j-th element.
The is a *fundamental* expectation for Python 2d containers.
Naturally we can eventually train people to expect anything,
but since I teach people to use Python,
I can tell you the current matrix behavior is a pain in the butt.
*Everyone* is surprised by the outcome of ``x[i][j]`` when x is a matrix.
(Ask yourself: weren't you the first time?)

In contrast, expectations about how nonscalar indexing works
are much less of a given.  And this is especially so if one
teaches matrices before arrays, which I generally do.
(More people are familiar with matrices.)
You can just teach people how nonscalar indexing produces
submatrices.  No sweat.

Related to this,
it is a *fairly* fundamental expectation that
iteration over a 2d Python object will yield
1d objects.  This very natural expectation is
met by ndarrays but not currently by matrices.

My proposal allows all these natural expectations
to be met.

Stefan's scores well too, so why do I prefer mine?
As I said, I am not sure mine is better, but I think it is,
an I can offer some reasons to prefer it.  Two are:

- it is simpler
- it retains more ndarray behavior

Simplicity is always good, for any given level of
functionality.  Keeping close to ndarray behavior is good,
since it means more transferable skills across the two types.

A third more personal reason is essentially aesthetic.
I like it when containers of a single type implement
containment as a weak order in the type hierarchy.
So I like that the less primitive matrix object would be
a container of more primitive ndarrays (when iterating).
Similarly, I like that ndarrays are containers of ndarrays.
In contrast Stefan's implementation will treat matrices as
containing a matrix subclass---a *less* primitive object, in
preference, and I offer it up in expectation that it will
garner some harsh criticism.  But there it is.

So that is my explanation.  But again, if Stefan implements
his proposal (tweaked as discussed), I will be quite pleased.

Cheers,
Alan

```