0

I am following a tutorial on how to work on multiple-precision arithmetic in Python.
In the end I would like to have a numpy array with floats of arbitrary high precision and I need to inverse that matrix.

Therefore we have:

import sys
import numpy as np
import gmpy2

print(sys.version)
print(np.__version__)
print(gmpy2.version)
3.6.10 | packaged by conda-forge | (default, Apr 24 2020, 16:27:41) 
[GCC Clang 9.0.1 ]
1.12.1
<built-in function version>

Followed by data generation:

A = np.ones((3,3));
B = A/gmpy2.mpfr("1.0")
print(A)
print(B)
[[ 1.  1.  1.]
 [ 1.  1.  1.]
 [ 1.  1.  1.]]
[[mpfr('1.0') mpfr('1.0') mpfr('1.0')]
 [mpfr('1.0') mpfr('1.0') mpfr('1.0')]
 [mpfr('1.0') mpfr('1.0') mpfr('1.0')]]

And the problematic part:

print(np.linalg.pinv(B))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-3a70ff54e53d> in <module>
----> 1 print(np.linalg.pinv(B))

~/conda-envs/Python_Jupyter/env/lib/python3.6/site-packages/numpy/linalg/linalg.py in pinv(a, rcond)
   1660     _assertNoEmpty2d(a)
   1661     a = a.conjugate()
-> 1662     u, s, vt = svd(a, 0)
   1663     m = u.shape[0]
   1664     n = vt.shape[1]

~/conda-envs/Python_Jupyter/env/lib/python3.6/site-packages/numpy/linalg/linalg.py in svd(a, full_matrices, compute_uv)
   1402 
   1403         signature = 'D->DdD' if isComplexType(t) else 'd->ddd'
-> 1404         u, s, vt = gufunc(a, signature=signature, extobj=extobj)
   1405         u = u.astype(result_t, copy=False)
   1406         s = s.astype(_realType(result_t), copy=False)

TypeError: No loop matching the specified signature and casting
was found for ufunc svd_n_s

Would anyone know how to achieve the goal I am working towards?

2
  • np.linalg probably is having problems with an array with object dtype, that is elements that aren't the numeric types used in its compiled code. sympy use mpmath for its high precision numeric work, but I don't know what that has for matrix inverse. Commented Oct 18, 2020 at 21:11
  • It might help to know what tutorial you are using, and how much of this particular task comes from there. Are they really suggesting using pinv? and on a singular array? Commented Oct 19, 2020 at 5:47

1 Answer 1

0

I have managed to inverse a matrix with very precise numbers with mpmath which contains a lot of built-in math functions as well as a matrix class. Thanks for the comments!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.