[Numpy-discussion] Strange Error with NumPy

David Warde-Farley dwf@cs.toronto....
Thu Aug 6 17:16:57 CDT 2009

On 6-Aug-09, at 6:01 PM, Nanime Puloski wrote:

> Can anyone explain to me why I receive an error(AtrributeError) in  
> NumPy
> when I do numpy.sin(2**64), but not when I do numpy.sin(2.0**64),
> numpy.sin(float(2**64)) or even numpy.sin(2)?

In [6]: type(2**64)
Out[6]: <type 'long'>

In [7]: type(2)
Out[7]: <type 'int'>

In [8]: type(2.0**64)
Out[8]: <type 'float'>

Probably because 2**64 yields a long, which is an arbitrary precision  
type in Python, and numpy is having trouble casting it to something it  
can use (it's too big for numpy.int64). Notice that np.sin(2**63 - 1)  
works fine while np.sin(2**63) doesn't - 2**63 - 1 is the largest  
value that an int64 can hold.

You're right that it could be approximately represented as a float32  
or float64, but numpy won't cast from exact types to inexact types  
without you telling it to do so.

I agree that the error message is less than ideal.


More information about the NumPy-Discussion mailing list