[Numpy-discussion] prerelease proposal for matrix behavior

Alan G Isaac aisaac at american.edu
Sat Apr 26 10:12:46 EDT 2008


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.

Cheers,
Alan






More information about the NumPy-Discussion mailing list