[Numpy-discussion] untenable matrix behavior in SVN

Keith Goodman kwgoodman at gmail.com
Tue Apr 29 16:15:21 EDT 2008


On Tue, Apr 29, 2008 at 12:50 PM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Tue, Apr 29, 2008 at 11:46 AM, Keith Goodman <kwgoodman at gmail.com> wrote:
>  > On Tue, Apr 29, 2008 at 11:21 AM, Alan G Isaac <aisaac at american.edu> wrote:
>  >  > On Tue, 29 Apr 2008, Keith Goodman apparently wrote:
>  >  >  > I often use x[i,:] and x[:,i] where x is a matrix and i is
>  >  >  > a scalar. I hope this continues to return a matrix.
>  >  >
>  >  >  1. Could you give an example of the circumstances of this
>  >  >  use?
>  >
>  >  In my use i is most commonly an array (i = M.where(y.A)[0] where y is
>  >  a nx1 matrix), sometimes a list, and in ipython when debugging or
>  >  first writing the code, a scalar. It would seem odd to me if x[i,:]
>  >  returned different types of objects based on the type of i:
>  >
>  >  array index
>  >  idx = M.where(y.A)[0] where y is a nx1 matrix
>  >  x[dx,:] -->  matrix
>  >
>  >  list index
>  >  idx = [0]
>  >  x[idx,:] --> matrix?
>  >
>  >  scalar index
>  >  idx = 0
>  >  x[idx,:] --> not matrix
>
>  Here's another use case:
>
>     for i in xrange(x.shape[1]):
>         xi = x[:,i]
>         idx = M.where(M.isfinite(xi).A)[0]
>         xi = xi[idx,:]
>         # more code
>
>  Also the functions I have written work on matrices. If x[i,:] did not
>  return a matrix, let's say it returned some other vector type object
>  that you index with a scalar, then my functions will have to test
>  whether the input is a full matrix or a vector since the indexing is
>  different.

And here's a use case that currently doesn't work but would be nice
(for me) if it did:

x[idx,i] = M.rand(2,1)

where x is a matrix, say 4x3, idx is an array with 2 elements, and i is a scalar



More information about the NumPy-Discussion mailing list