[Numpy-discussion] Bitwise operations and unsigned types

Travis Oliphant travis at continuum.io
Fri Apr 6 01:16:34 EDT 2012


Which version of NumPy are you using.  This could be an artefact of the new casting rules.     

This used to work.   So, yes, this is definitely a bug. 

-Travis

On Apr 5, 2012, at 10:54 PM, Chris Laumann wrote:

> 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
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120406/d5421c16/attachment.html>


More information about the NumPy-Discussion mailing list