Storing integers larger than 64 bits in NumPy array

Viewed 469

It is apparent that NumPy has an upper bound for its integers. But my question is, is there a way to store the elements in NumPy arrays, like by keeping the values and the magnitudes separate? Wouldn't that technically allow storing of larger numbers than what the int64 limit allows?

1 Answers

for example you can store arbitrary precision integers in numpy array using dtype = object and perform addition, multiplication, element-wise multiplication, subtraction and integer division but not operations, which lead to float results, for example np.exp(x) wont work.

x = np.ones((10,10),dtype=object)

x *= 2**100

x *= x

print(x)

if you want truly arbitrary precision arithmetic matrix classes I would implement on my own with proper operator overload with help of mpmath

Related