[Numpy-discussion] Strange Error with NumPy
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
> 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 : type(2**64)
Out: <type 'long'>
In : type(2)
Out: <type 'int'>
In : type(2.0**64)
Out: <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