我正在學(xué)習(xí)有關(guān)如何在 Python 中進(jìn)行多精度算術(shù)的教程。最后,我想要一個(gè)numpy具有任意高精度浮點(diǎn)數(shù)的數(shù)組,并且我需要反轉(zhuǎn)該矩陣。因此我們有:import sysimport numpy as npimport gmpy2print(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>接下來是數(shù)據(jù)生成: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 castingwas found for ufunc svd_n_s有人知道如何實(shí)現(xiàn)我正在努力的目標(biāo)嗎?
1 回答

慕尼黑的夜晚無繁華
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
我已經(jīng)成功地用非常精確的數(shù)字來反轉(zhuǎn)矩陣,其中mpmath
包含許多內(nèi)置數(shù)學(xué)函數(shù)以及矩陣類。感謝您的評(píng)論!
添加回答
舉報(bào)
0/150
提交
取消