'Is there a way to make a complex number in NumPy with the accuracy of a Decimal type?

I'm working in Python with NumPy arrays of complex numbers that extend well past the normal floating point limits of NumPy’s default Complex type (numbers greater than 10^500). I wanted to know if there was some way I could extend NumPy so that it will be able to handle complex numbers with this sort of magnitude. For example, is there a way to make a NumPy complex type that uses functionality from the Decimal module?

I know there are resources available such as mpmath that could probably do what I need. However, it is a requirement of my project that I use NumPy.

For anyone that's interested in why I need these enormous numbers, it's because I'm working on a numerical relativity simulation of the early universe.



Solution 1:[1]

Depending on your platform, you may have support for complex192 and/or complex256. These are generally not available on Intel platforms under Windows, but they are on some others—if your code is running on Solaris or on a supercomputer cluster, it may support one of these types. On Linux, you may even find them available or you could create your array using dtype=object and then use bigfloat or gmpy2.mpc.

  1. complex256 numbers up to 104932 + 104932j
  2. complex192 ditto, but with less precision
  3. I have even seen mention of NumPy and complex512...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Mortensen