<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 27, 2013 at 8:27 AM, Sebastian Berg <span dir="ltr"><<a href="mailto:sebastian@sipsolutions.net" target="_blank">sebastian@sipsolutions.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey,<br>
<br>
since I am working on the indexing. I was wondering about a few smaller<br>
things:<br>
<br>
* 0-d boolean array, `np.array(0)[True]` (will work now) would<br>
give np.array([0]) as a copy, instead of the original array.<br>
I guess I could add a FutureWarning or so, but I am not sure<br>
and overall the chance of creating bugs seems low.<br>
<br>
(The boolean index should always add 1 dimension and here,<br>
remove 0 dimensions -> 1-d result.)<br>
<br>
* All index operations return a view; never the object. This<br>
means that `v = arr[...]` is slightly slower. But since it<br>
does not affect `arr[...] = vals`, I think the speed<br>
implications are negligible.<br>
<br>
* Does anyone have an idea if there is a way to change the subclass<br>
logic that view based item setting is implemented as:<br>
np.asarray(subclass[index]) = vals<br>
<br>
I somewhat think the subclass should rather implement `__setitem__`<br>
instead of relying on numpy calling its `__getitem__`, but I<br>
don't see how it can be changed.<br>
<br>
* Still thinking a bit about implementing a keepdims keyword or<br>
function, to handle matrix type logic mostly in the C-code.<br>
<br>
And most importantly, is there any behaviour thing in the index<br>
machinery that is bugging you, which I may have forgotten until now?<br>
<br>
- Sebastian<br>
<br></blockquote><div><br></div><div>Boolean indexing could use a facelift. First, consider the following (albeit minor) annoyance:<br><br>>>> import numpy as np<br>>>> a = np.arange(5)<br>>>> a[[True, False, True, False, True]]<br>
array([1, 0, 1, 0, 1])<br>>>> b = np.array([True, False, True, False, True])<br>>>> a[b]<br>array([0, 2, 4])<br><br></div><div>Next, it would be nice if boolean indexing returned a view (wishful thinking, I know):<br>
<br>>>> c = a[b]<br>>>> c<br>array([0, 2, 4])<br>>>> c[1] = 7<br>>>> c<br>array([0, 7, 4])<br>>>> a<br>array([0, 1, 2, 3, 4])<br><br></div><div>Cheers!<br>Ben Root<br></div></div>
</div></div>