[Numpy-discussion] untenable matrix behavior in SVN
Anne Archibald
peridot.faceted@gmail....
Fri Apr 25 14:19:43 CDT 2008
On 25/04/2008, Charles R Harris <charlesr.harris@gmail.com> wrote:
>
>
> On Fri, Apr 25, 2008 at 12:02 PM, Alan G Isaac <aisaac@american.edu> wrote:
> > I think we have discovered that there is a basic conflict
> > between two behaviors:
> >
> > x[0] == x[0,:]
> > vs.
> >
> > x[0][0] == x[0,0]
> >
> > To my recollection, everyone has agree that the second
> > behavior is desirable as a *basic expectation* about the
> > behavior of 2d objects. This implies that *eventually* we
> > will have ``x[0][0] == x[0,0]``. But then eventually
> > we MUST eventually have x[0] != x[0,:].
> >
> Choices:
>
> 1) x[0] equiv x[0:1,:] -- current behavior
> 2) x[0] equiv x[0,:] -- array behavior, gives x[0][0] == x[0,0]
>
> These are incompatible. I think 1) is more convenient in the matrix domain
> and should be kept, while 2) should be given up. What is the reason for
> wanting 2)? Maybe we could overload the () operator so that x(0) gives 2)?
> Or vice versa.
We are currently operating in a fog of abstraction, trying to decide
which operations are more "natural" or more in correspondence with our
imagined idea of a user. We're not getting anywhere. Let's start
writing up (perhaps on the matrix indexing wiki page) plausible use
cases for scalar indexing, and how they would look under each
proposal.
For example:
* Iterating over the rows of a matrix:
# array-return proposal; x is a scalar
for row in M:
if np.all(row==0):
raise ValueError
# exception-raising proposal
for i in xrange(M.shape[0]):
if np.all(M[i,:]==0):
raise ValueError
Other applications?
Anne
More information about the Numpy-discussion
mailing list