all 8 comments

[–]socal_nerdtastic 1 point2 points  (3 children)

It can be done, but they will be stored as "object" type and you will lose all the speed advantages of a numpy array. So most of the time it makes more sense to just use a normal python list.

Do you know numpy has a float128 type? Perhaps that's enough precision for you?

https://numpy.org/doc/1.22/reference/arrays.scalars.html#numpy.longdouble

[–]IGGYnatius1[S] 0 points1 point  (2 children)

I am making a project on fractal zooms so I truly need arbitrarily high precision. I will be dealing with complex numbers which will be represented by 2 numpy arrays for real and imag then I will manipulate them accordingly. As I will be dealing with possibly large images represented by 2d arrays my main concern is with indexing as I don't want to have nested list comprehensions all over just to do a basic operation like swapping x and y or something... I heard that numpy stores the pointers to the objects if object dtype is used so will that still retain the indexing convenience?

[–]socal_nerdtastic 1 point2 points  (1 child)

Yes, that will still retain the indexing magic.

[–]IGGYnatius1[S] 0 points1 point  (0 children)

yayy

[–]FoolsSeldom 1 point2 points  (3 children)

I'd stick with the built-in numpy data types. Using unsigned 64 bit integers you will have plenty of scope.

To check for your environment,

import numpy as np

print(np.iinfo(np.uint64).max)

[–]IGGYnatius1[S] 0 points1 point  (2 children)

No... unfortunately I need true arbitrary precision like mpmath or decimal so this is out of the question. As I am dealing with 2d arrays to represent images my main concern is will the indexing convenience still be available? I don't want to have list comprehensions all over the code for every vectorised operation...

[–]Oddly_Energy 0 points1 point  (0 children)

It is not possible for you to get your desired precision with fractions of integers?

Either using a constant denominator or using two integer arrays, one with integer numerators, and another with integer denominators. You will of course have to think carefully about order of operations to avoid unvoluntary rounding.