I have a numpy array of floats of arbitrary precision (dtype=object). How do I convert this array of floats with arbitrary precision to array of integers? a = np.array([10662878767676765765756765768768787987, 1068768988765462575276572656879287982,..], dtype= object) b = a*821627.1218279279222972 a = b.astype(int) How do I round off b to get back array of integers without losing precision?
np.astype gives me the following error:
Overflowerror: Python int too large to convert to C long.
Thanks much for the help!
floatis fixed-precision, as is anything floating-point in NumPy.np.int64will allow for larger ints, but note that, as far as I know, NumPy won't let you have truly arbitrary precision ints. Using 64 bit ints moves the limit a lot higher, but there will still be a limit.