[Numpy-discussion] Release of NumPy
Stéfan van der Walt
stefan@sun.ac...
Wed Apr 16 03:35:02 CDT 2008
On 16/04/2008, Alan G Isaac <aisaac@american.edu> wrote:
> > The whole issue occurs because a Matrix is not a proper
> > container.
>
>
> Right. And *that* is the case because of the attempt to
> treat matrices as containers of matrices instead of as
> containers of 1d arrays.
>
> I can see no real advantage to having matrices be containers
> of row vectors instead. A row vector would just be a matrix
> (i.e., essentially 2d) that allowed 1d style indexing.
> Again I ask, have you ever needed such a thing?
In the Matrix world, there is no such thing as an (N,) array -- which
is why the current Matrix object behaves so strangely, and always
returns a result with ndim > 1.
Your proposal suggests that a Matrix be a container of arrays, but it
does not address the slicing of column vectors, i.e.
x[0]
x[0,:]
x[:,0]
would then behave in completely different ways, whereas with ndarrays
they don't.
If you modified the proposal to say "any slicing operation that
returns a (1,N) or (N,1) matrix should now return an (N,) ndarray", it
would be more consistent, but then, wouldn't that break some other
expected behaviour? I thought one of the powerful features of a
matrix is that it preserves the orientation of a vector slice?
The only way I've seen so far to have consistent slicing, is to have
an N-dim Matrix object be a container of N-1 dim Matrices, up to the
2-D case, in which it becomes a container of Vectors which, in turn,
contain scalars.
> I agree this is a good perspective. (But *two* operators: * and **.)
> It implies: there are deviations from array behavior that
> are buying us nothing. This is my point.
Yup, and fortunately we now have both those implemented for arrays as well :)
Regards
Stéfan
More information about the Numpy-discussion
mailing list