I came across an unpredicted AttributeError
when using the arccosh
in Numpy. Here it is with Python 2:
>>> from numpy import arccosh
>>> arccosh(123456789012345678901)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'long' object has no attribute 'arccosh'
I found a similar error in Python 3.
Making the number a bit lower helps:
>>> arccosh(12345678901234567890)
44.65298496976247
While floats also works:
>>> arccosh(10**20)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'arccosh'
>>> arccosh(10.**20)
46.74484904044086
The exception also pops up for other functions, e.g., arcsinh
, log10
and sin
.
I suppose that the numbers are too long for numpy.uint64
>>> big = np.array([10**18], dtype=np.uint64)
>>> big = np.array([10**20], dtype=np.uint64)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C long
and that Numpy does not handle the numpy.object
.
>>> big = np.array([10**20], dtype=np.object)
>>> arccosh(big)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'arccosh'
Python's acosh
in the math
module works:
>>> from math import acosh
>>> acosh(10**20)
46.74484904044086
I see an explanation here AttributeError: 'numpy.float64' object has no attribute 'log10' so while the error is explanable it is a bit surprising.