我正在学习有关如何在 Python 中进行多精度算术的教程。最后,我想要一个numpy具有任意高精度浮点数的数组,并且我需要反转该矩阵。因此我们有: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>接下来是数据生成: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有人知道如何实现我正在努力的目标吗?
添加回答
举报
0/150
提交
取消