[Numpy-discussion] Indexing changes/deprecations
Benjamin Root
ben.root at ou.edu
Fri Sep 27 09:26:56 EDT 2013
On Fri, Sep 27, 2013 at 8:27 AM, Sebastian Berg
<sebastian at sipsolutions.net>wrote:
> Hey,
>
> since I am working on the indexing. I was wondering about a few smaller
> things:
>
> * 0-d boolean array, `np.array(0)[True]` (will work now) would
> give np.array([0]) as a copy, instead of the original array.
> I guess I could add a FutureWarning or so, but I am not sure
> and overall the chance of creating bugs seems low.
>
> (The boolean index should always add 1 dimension and here,
> remove 0 dimensions -> 1-d result.)
>
> * All index operations return a view; never the object. This
> means that `v = arr[...]` is slightly slower. But since it
> does not affect `arr[...] = vals`, I think the speed
> implications are negligible.
>
> * Does anyone have an idea if there is a way to change the subclass
> logic that view based item setting is implemented as:
> np.asarray(subclass[index]) = vals
>
> I somewhat think the subclass should rather implement `__setitem__`
> instead of relying on numpy calling its `__getitem__`, but I
> don't see how it can be changed.
>
> * Still thinking a bit about implementing a keepdims keyword or
> function, to handle matrix type logic mostly in the C-code.
>
> And most importantly, is there any behaviour thing in the index
> machinery that is bugging you, which I may have forgotten until now?
>
> - Sebastian
>
>
Boolean indexing could use a facelift. First, consider the following
(albeit minor) annoyance:
>>> import numpy as np
>>> a = np.arange(5)
>>> a[[True, False, True, False, True]]
array([1, 0, 1, 0, 1])
>>> b = np.array([True, False, True, False, True])
>>> a[b]
array([0, 2, 4])
Next, it would be nice if boolean indexing returned a view (wishful
thinking, I know):
>>> c = a[b]
>>> c
array([0, 2, 4])
>>> c[1] = 7
>>> c
array([0, 7, 4])
>>> a
array([0, 1, 2, 3, 4])
Cheers!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130927/1eec1620/attachment.html>
More information about the NumPy-Discussion
mailing list