Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79264 > unrolled thread

Re: Extract Indices of Numpy Array Based on Given Bit Information

Started byArtur Bercik <vbubbly21@gmail.com>
First post2014-10-18 15:42 +0900
Last post2014-10-18 15:42 +0900
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Extract Indices of Numpy Array Based on Given Bit Information Artur Bercik <vbubbly21@gmail.com> - 2014-10-18 15:42 +0900

#79264 — Re: Extract Indices of Numpy Array Based on Given Bit Information

FromArtur Bercik <vbubbly21@gmail.com>
Date2014-10-18 15:42 +0900
SubjectRe: Extract Indices of Numpy Array Based on Given Bit Information
Message-ID<mailman.14962.1413620435.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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@gmail.com> wrote:

> On Sat, Oct 18, 2014 at 4:58 PM, Artur Bercik <vbubbly21@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
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web