Extract Indices of Numpy Array Based on Given Bit Information
Artur Bercik
vbubbly21 at gmail.com
Sat Oct 18 08:42:00 CEST 2014
Thanks Chris Angelico for your nice answer.
I got some sense, but could not imagine if required Bit No. 2–5, and Bit
Combination 0000.
I hope example with the new case would make me more sense.
Artur
On Sat, Oct 18, 2014 at 3:24 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Oct 18, 2014 at 4:58 PM, Artur Bercik <vbubbly21 at gmail.com> wrote:
> > I want to get the index of my data where the following occurs:
> >
> > Bit No. 0–1
> > Bit Combination: 00
>
> So, what you want to do is look at each number in binary, and find the
> ones that have two zeroes in the last two places?
> 1073741824: 1000000000000000000000000000000
> 1073741877: 1000000000000000000000000110101
>
> The easiest way to do this is with simple bitwise operations:
>
> >>> 1073741824 & 3
> 0
> >>> 1073741877 & 3
> 1
>
> 3 is 0000000000000011 in binary, so a bitwise AND with that will tell
> you about just the last two bits. The result will be an integer - 0,
> 1, 2, or 3, representing 00, 01, 10, or 11 for those last two bits. So
> all you have to do is AND each number with 3, and when the result is
> 0, that's what you want.
>
> Does that make sense?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141018/73cc7b80/attachment.html>
More information about the Python-list
mailing list