<p dir="ltr">It sounds like you're using an old version of numpy, where boolean scalars were interpreted as integers.</p>
<p dir="ltr">What version are you using?</p>
<p dir="ltr">Eric</p>
<br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 14, 2017, 04:27 Joe <<a href="mailto:solarjoe@posteo.org">solarjoe@posteo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
thanks for you feedback.<br>
<br>
Sorry, if thie question is stupid and the case below does not make<br>
sense.<br>
I am just trying to understand the logic.<br>
For<br>
<br>
x = np.random.rand(2,3)<br>
<br>
x[True]<br>
x[(True,)]<br>
<br>
or<br>
<br>
x[False]<br>
x[(False,)]<br>
<br>
where True and False are not arrays,<br>
it will pick the first or second row.<br>
<br>
Is this basic indexing then with one the rules<br>
- obj is an integer<br>
- obj is a tuple of slice objects and integers.<br>
?<br>
<br>
<br>
Am 13.12.2017 21:49 schrieb Eric Wieser:<br>
> Increasingly, NumPy does not considers booleans to be integer types,<br>
> and indexing is one of these cases.<br>
><br>
> So no, it will not be treated as a tuple of integers, but as a 0d mask<br>
><br>
> Eric<br>
><br>
> On Wed, 13 Dec 2017 at 12:44 Joe <<a href="mailto:solarjoe@posteo.org" target="_blank">solarjoe@posteo.org</a>> wrote:<br>
><br>
>> Hi,<br>
>><br>
>> yet another question.<br>
>><br>
>> I looked through the indexing rules in the<br>
>> documentation but I count not find which one<br>
>> applies to x[True] and x[False]<br>
>><br>
>> that might e.g result from<br>
>><br>
>> import numpy as np<br>
>> x = np.array(3)<br>
>> x[x>5]<br>
>> x[x<1]<br>
>> x[True]<br>
>> x[False]<br>
>><br>
>> x = np.random.rand(2,3)<br>
>> x[x>5]<br>
>> x[x<1]<br>
>> x[True]<br>
>> x[False]<br>
>><br>
>> I understood that they are equivalent to<br>
>><br>
>> x[(False,)]<br>
>><br>
>> I tested it and it looks like advanced indexing,<br>
>> but I try to unterstand the logic behind this,<br>
>> if there is any :)<br>
>><br>
>> In x[x<1] the x<1 is a mask and thus I guess it is a<br>
>> "tuple with at least one sequence object or ndarray (of data type<br>
>> integer or bool)", right?<br>
>><br>
>> Or will x[True] trigger basic indexing as it is "a tuple of<br>
>> integers"<br>
>> because True will be converted to Int?<br>
>><br>
>> Cheers,<br>
>> Joe<br>
>> _______________________________________________<br>
>> NumPy-Discussion mailing list<br>
>> <a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
>> <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a> [1]<br>
><br>
><br>
> Links:<br>
> ------<br>
> [1] <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
><br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>