Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'suppose': 0.07; 'bits': 0.09; 'cc:addr:python-list': 0.11; 'binary,': 0.16; 'did,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sense,': 0.16; 'zero.': 0.16; 'zeroes': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'there.': 0.32; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'combination': 0.36; 'pm,': 0.38; 'does': 0.39; 'hope': 0.61; 'new': 0.61; 'no.': 0.61; 'numbers': 0.61; "you're": 0.61; 'more': 0.64; 'to:none': 0.92; 'imagine': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=FMIBzkk8NhUKY8zeEzXIvAcn2z8DAkZPdwlCvAkXV+Y=; b=ckaSs1gcpXBVVM7hEIchSLai3BYIUp8WF3xvC561vxOndfGwPSJdvL2GziVB6zS+cI ZGBwoQ/q3HMgv+Z7AlVkFmA+sIMRJNIcMW1/UkuVH8LZwiTpIdxQHesoX44qwIzMKWDw lyFHOD9mjbCqRHZv9dbDyblBS5j4s9UUKaaxMTGMeIOUwCQo6sxSLlU7vwzUYng96zag So7kg4GkxApTR0MiSa42vD6uIXKdi52q4iM5Xq0ZACSYLDYPxWRBDZyqztnc21ns6v0T elgn1v1xTcb8VRF+4gVQuWMONnFK2XmXpg4pP80N+8Ow1Q8csuWFn2Z0uo/Nu1M4uw8q RjGQ== MIME-Version: 1.0 X-Received: by 10.50.60.97 with SMTP id g1mr3924911igr.2.1413615047593; Fri, 17 Oct 2014 23:50:47 -0700 (PDT) In-Reply-To: References: Date: Sat, 18 Oct 2014 17:50:47 +1100 Subject: Re: Extract Indices of Numpy Array Based on Given Bit Information From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413615055 news.xs4all.nl 2851 [2001:888:2000:d::a6]:47459 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 3126571458 X-Received-Bytes: 3961 Xref: csiph.com comp.lang.python:79258 On Sat, Oct 18, 2014 at 5:42 PM, Artur Bercik wrote: > I got some sense, but could not imagine if required Bit No. 2=E2=80=935, = and Bit > Combination 0000. > > I hope example with the new case would make me more sense. > Just write the number in binary, with the bits you're interested in set to 1, and everything else 0: ... 876543210 ... 000111100 >>> 0b000111100 60 >>> 1073741877 & 0b000111100 52 So this number does _not_ have all zeroes there. If it did, the result would be zero. To look for some other pattern, just do the same thing - suppose we want to find numbers where it's 1001, we just look for the result to be 0b000100100, or 36. ChrisA