[Numpy-discussion] matrix wart
Travis E. Oliphant
oliphant at enthought.com
Fri Feb 22 10:22:29 EST 2008
>
>> Could you explain to me how you'd like this to be fixed? If the
>> matrix becomes a container of 1-d arrays, then you can no longer
>> expect x[:,0] to return a column vector -- which was one
>> of the reasons the matrix class was created. While not
>> entirely consistent, one workaround would be to detect
>> when a matrix is a "vector", and then do 1-d-like indexing
>> on it.
>>
>
>
>
> Letting M be a matrix and A=M.A, and i and j are integers.
> I would want two principles to be honored.
>
> 1. ordinary Python indexing produces unsurprising results,
> so that e.g. M[0][0] returns the first element of the matrix
> 2. indexing that produces a 2-d array when applied to A
> will produce the equivalent matrix when applied to M
>
> There is some tension between these two requirements,
> and they do not address your specific example.
>
> Various reconciliations can be imagined.
> I believe a nice one can be achieved with
> a truly minimal change, as follows.
>
> Let M[i] return a 1d array. (Unsurprising!)
> This is a change: a matrix becomes a container
>
This is a concrete proposal and I don't immediately have a problem with
it (other than it will break code and so must go in to 1.1).
> Let M[:,i] and M[i,:] behave as now.
>
Some would expect M[i,:] and M[i] to be the same thing, but I would be
willing to squelsh those expectations if many can agree that M[i] should
return an array.
> In addition, as a consistency measure, one might
> ask that M[i,j] return a 1 x 1 matrix. (This is
> of secondary importance, but it follows the
> principle that the use of multiple indexes
> produces matrices.)
>
I'm pretty sure that wasn't the original "principle", but again this is
not unreasonable.
> Right now I'm operating on caffeine instead of sleep,
> but that looks right ...
>
> Alan Isaac
>
>
More information about the NumPy-Discussion
mailing list