Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to deal with large integers in NumPy?

I’m doing a data analysis project where I’m working with really large numbers. I originally did everything in pure python but I’m now trying to do it with numpy and pandas. However it seems like I’ve hit a roadblock, since it is not possible to handle integers larger than 64 bits in numpy (if I use python ints in numpy they max out at 9223372036854775807). Do I just throw away numpy and pandas completely or is there a way to use them with python-style arbitrary large integers? I’m okay with a performance hit.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

by default numpy keeps elements as number datatype.
But you can force typing to object, like below

import numpy as np
x = np.array([10,20,30,40], dtype=object)
x_exp2 = 1000**x
print(x_exp2)

the output is

[1000000000000000000000000000000
 1000000000000000000000000000000000000000000000000000000000000
 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]

The drawback is that the execution is much slower.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading