<div dir="ltr">Dear Julian Taylor<div><br></div><div>Thank you very much, I really appreciated your codes.</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 18, 2014 at 9:28 PM, Julian Taylor <span dir="ltr"><<a href="mailto:jtaylor.debian@googlemail.com" target="_blank">jtaylor.debian@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 18.10.2014 14:14, Artur Bercik wrote:<br>
><br>
><br>
> On Sat, Oct 18, 2014 at 9:00 PM, Artur Bercik <<a href="mailto:vbubbly21@gmail.com">vbubbly21@gmail.com</a><br>
</span><span class="">> <mailto:<a href="mailto:vbubbly21@gmail.com">vbubbly21@gmail.com</a>>> wrote:<br>
><br>
><br>
><br>
> On Sat, Oct 18, 2014 at 8:28 PM, Julian Taylor<br>
> <<a href="mailto:jtaylor.debian@googlemail.com">jtaylor.debian@googlemail.com</a><br>
</span><span class="">> <mailto:<a href="mailto:jtaylor.debian@googlemail.com">jtaylor.debian@googlemail.com</a>>> wrote:<br>
><br>
> On 18.10.2014 07:58, Artur Bercik wrote:<br>
> > Dear Python and Numpy Users:<br>
> ><br>
> > My data are in the form of '32-bit unsigned integer' as follows:<br>
> ><br>
> > myData = np.array([1073741824, 1073741877, 1073742657, 1073742709,<br>
> > 1073742723, 1073755137, 1073755189,1073755969],dtype=np.int32)<br>
> ><br>
> > I want to get the index of my data where the following occurs:<br>
> ><br>
> > Bit No. 0–1<br>
> > Bit Combination: 00<br>
> ><br>
> > How can I do it? I heard this type of problem first time, please help me.<br>
> ><br>
> > Artur<br>
> ><br>
><br>
> not sure I understand the problem, maybe this?<br>
><br>
> np.where((myData & 0x3) == 0)<br>
><br>
><br>
> yes, it works greatly for the following case:<br>
><br>
> myData = np.array([1073741824, 1073741877, 1073742657, 1073742709,<br>
> 1073742723, 1073755137, 1073755189,1073755969],dtype=np.uint32)<br>
> Bit No. 0–1<br>
> Bit Combination: 00<br>
><br>
> Can you make such automation for the following case as well?<br>
><br>
> Bit No. 2–5<br>
> Bit Combination: 1101<br>
><br>
<br>
</span>sure, you can do any of these with the right masks:<br>
np.where((myData & 0x3c) == 0x34)<br>
<br>
you can use bin(number) to check if your numbers are correct.<br>
<span class=""><br>
<br>
><br>
> Also wondering why np.where((myData & 0x3) == 0) instead of<br>
> just np.where((myData & 3) == 0)<br>
><br>
<br>
</span>its the same, 0x means the number is in hexadecimal representation, for<br>
3 they happen to be equal (as 3 < 10)<br>
It is often easier to work in the hexadecimal representation when<br>
dealing with binary data as its base is a power of two. So two digits in<br>
hexadecimal represent one byte.<br>
In the case above: 0x3c<br>
c is 12 -> 1100<br>
3 is 3 -> 11<br>
together you get 111100, mask for bits 2-5<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div></div></div>