[Numpy-discussion] Bitwise operations and unsigned types

Chris Laumann claumann@physics.harvard....
Thu Apr 5 22:54:18 CDT 2012

Hi all- 

I've been trying to use numpy arrays of ints as arrays of bit fields and mostly this works fine. However, it seems that the bitwise_* ufuncs do not support unsigned integer dtypes:

In [142]: np.uint64(5)&3
TypeError                                 Traceback (most recent call last)
/Users/claumann/<ipython-input-142-65e3301d5d07> in <module>()
----> 1 np.uint64(5)&3

TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

This seems odd as unsigned ints are the most natural bitfields I can think of -- the sign bit is just confusing when doing bit manipulation. Python itself of course doesn't make much a distinction between ints, longs, unsigned etc.

Is this a bug?

Thanks, Chris 

Chris Laumann
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120405/1446dfd1/attachment.html 

More information about the NumPy-Discussion mailing list