对使用sypy矩阵时出现类型错误纽比.利纳格.艾格

2024-09-30 18:34:58 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码可以正常工作

import numpy.linalg as nplin
T = [[1,0],[0,1]]
nplin.eig(T)

从而产生输出

^{pr2}$

但是如果我试图使用sympy中的Matrix对象

import numpy.linalg as nplin
from sympy import Matrix
T = Matrix([[1,0],[0,1]])
nplin.eig(T)

我得到以下错误

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

即使我把SymPy矩阵对象转换成NumPy数组

import numpy.linalg as nplin
import numpy
from sympy import Matrix
T = numpy.array(Matrix([[1,0],[0,1]]))
nplin.eig(T)

我还是犯了同样的错误。这里有什么问题?在

我正在使用Python 2.7.9NumPy 1.8.2和{}。在


Tags: the对象fromimportnumpyas错误not