# [Numpy-discussion] prerelease proposal for matrix behavior

Timothy Hochberg tim.hochberg@ieee....
Mon Apr 28 13:54:37 CDT 2008

```On Sat, Apr 26, 2008 at 7:12 AM, Alan G Isaac <aisaac@american.edu> wrote:

> On Fri, 25 Apr 2008, "Travis E. Oliphant" apparently wrote:
> > At this point, I'm leaning in the direction of the
> > RowVector / ColumnVector approach (even if these are not
> > really advertised and just used during indexing).
>
> I believe that this conflicts with submatrix extraction.
> Details follow.
>
> Suppose ``x`` is a matrix, and I say ``v=A[0]``.
> What is ``v``?
>
> 1. If ``v`` is a 1d array, its behavior is known.
> E.g., ``v[0]`` is the first element
> and ``v[0,0]`` is an IndexError.
> If we want to keep submatrix extraction (as we should),
> we give up ``x[0] == x[0,:]``.
>
> 2. If ``v`` is a matrix, its behavior can be learned
> by the experienced but breaks basic expectations
> (the x[0][0] problem).
>
> 3. If ``v`` is a "RowVector" what behavior do we get?
> Suppose the idea is that this will rescue
> ``x[0][0]==x[0,0]`` **and** ``x[0]=x[0,:]``.
> But then we must give up that ``x[0,:]`` is a submatrix.
> Must ``v`` deviate from submatrix behavior in an important way?
> Yes:  ``v[0][0]`` is an IndexError.
> (Note that the same problem arises if we just override
> ``__getitem__`` for the matrix class to special case
> row and column matrices.)
>
> Since submatrix extraction is fundamental, I think it is
> a *very* bad idea to give it up.  If so, then under the
> RowVector proposal we must give up ``x[0]==x[0,:]``.
> But this is just what we give up with
> the much simpler proposal that ``v`` be a 1d array.
>

I may have missed something since I've been getting these emails all out of
order for some reason and it's been hard to follow. Can you clarify what you
mean by submatrix extraction? It sounds like you want to be able index into
an MxN array and get out a 1xN or Mx1 matrix. If that's the case, wouldn't
the natural way to spell that under the RowVector/ColumnVector approach (and
most others that I can think of) be:

m2 = m1[:1]

or

m2 = m1[:,:1]

Here we're extracting the first row and column respectively as a matrix.
This doesn't appear to have any of the conflicts with row/vector extraction
and in general meshes much better with arrays than having some magic
associated with appending an extra ':', which seems ill advised to me.

--
. __
. |-\
.
. tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080428/0d4a031e/attachment.html
```