Python:用高精度浮点数逆矩阵

Python: inverse a matrix with high precision floats

我正在学习如何在 Python 中进行多精度运算的教程。
最后,我想要一个具有任意高精度浮点数的 numpy 数组,我需要对该矩阵求逆。

因此我们有:

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>

接着是数据生成:

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')]]

以及有问题的部分:

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

有人知道如何实现我正在努力实现的目标吗?

我已经成功地用 mpmath 对一个包含很多 built-in 数学函数和矩阵 class 的非常精确的数字求逆矩阵。感谢评论!