[Numpy-discussion] take semantics (bug?)
Michael McNeil Forbes
mforbes at phys.washington.edu
Tue Dec 5 20:57:10 CST 2006
Robert Kern <robert.kern at gmail.com> wrote:
> Michael McNeil Forbes wrote:
> > What are the semantics of the "take" function?
> > I would have expected that the following have the same shape and size:
> >>>> a = array([1,2,3])
> >>>> inds = a.nonzero()
> >>>> a[inds]
> > array([1, 2, 3])
> >>>> a.take(inds)
> > array([[1, 2, 3]])
> > Is there a bug somewhere here or is this intentional?
> It's a result of a.nonzero() returning a tuple.
> __getitem__ interprets tuples specially: a[1,2,3] == a[(1,2,3)], also a[0,]
> == a.
> .take() doesn't; it simply tries to convert its argument into an array. It
> convert (array([0, 1, 2]),) into array([[0, 1, 2]]), so it does.
Okay. I understand why this happens from the code.
1) Is there a design reason for this inconsistent treatment of "indices"?
2) If so, is there some place (perhaps on the Wiki or in some source
code I cannot find) that design decisions like this are discussed? (I
have several other inconsistencies I would like to address, but would
like to find out if they are "intentional" before wasting people's time.)
More information about the Numpy-discussion