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.
Numpy library gives us functions such as real() and imag() to find real and imaginary parts of a complex number.
NumPy supports a much greater variety of numerical types than Python does. This section shows which are available, and how to modify an array's data-type. Platform-defined double precision float: typically sign bit, 11 bits exponent, 52 bits mantissa.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With