[Numpy-discussion] matrices in 1.1

Charles R Harris charlesr.harris@gmail....
Sat Mar 22 20:07:39 CDT 2008


On Sat, Mar 22, 2008 at 7:02 PM, Alan G Isaac <aisaac@american.edu> wrote:

> > On Sat, Mar 22, 2008 at 5:49 PM, Alan G Isaac
> > <aisaac@american.edu> wrote:
> >>  Are you trying to suggest that in most matrix programming
> >>  languages if you extract a row you will then need to use two
> >>  indices to extract an element of that row?  This does not
> >>  match my experience.  I would ask you to justify that by
> >>  listing the languages you have in mind.
>
> On Sat, 22 Mar 2008, Stéfan van der Walt apparently wrote:
> > No, I agree with you that that is unintuitive -- but it can be solved
> > by introducing Row and ColumnVectors, which are still 2-dimensional.
>
> To me, this seems to be adding a needless level of
> complexity.  I am not necessarily opposing it;
> I just do not see a commensurate payoff.
> In contrast, I see great payoff to keeping as much
> ndarray behavior as possible.
>
>
> > One important result you don't want is:
> > In [9]: x = np.array([[1,2,3],[4,5,6],[7,8,9]])
> > In [10]: x[:,0]
> > Out[10]: array([1, 4, 7])
>
> Agreed.  I would hope it has been clear from earlier
> discussion that the proposal retains that any use
> of multiple indexes will produce a 2d submatrix.
> That offers a simple way to say how matrix indexing
> will differ from ndarray indexing.
>
>
> > Do I understand correctly that you want M[0,:] and M[0] to
> > behave differently?
>
> Yes.  Again, I think that I have been consistent on this point.
> Any use of multiple indexes such as M[0,:] will produce a 2d submatrix.
> Any use of scalar indexes such as M[0] behave as with an ndarray.
>
>
> > Would you like M[0] to return the first element of the
> > matrix as in Octave?
>
> No!
> Deviations from ndarray behavior should be minimized.
> They should be:
>
> 1. Multiplication is redefined to matrix multiplication.
> 2. Powers are redefined accordingly.
> 3. The ``A`` and ``I`` attributes.
> 4. Any use of multiple indexes will produce a 2d submatrix.
>
> I think that is it.
>
>
> > If I'm the only one who is not completely satisfied, then
> > please, submit a patch and have it applied.
>
> Always a reasonable request, but with respect to NumPy, I'm
> a user not a developer.  That said, it looks to be simple:
> perhaps no more than adding to __getitem__ after the
> existing lines::
>
>        if not isinstance(out, N.ndarray):
>            return out
>
> two new lines::
>
>        if isscalar(index):
>            return out
>
> (Not that I like multiple points of return from a function.)
>

All this for want of an operator ;)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080322/442296e4/attachment.html 


More information about the Numpy-discussion mailing list