Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 计算Numpy中的特征值无效:每个元素都是一个浮点_Python_Python 2.7_Numpy_Linear Algebra - Fatal编程技术网

Python 计算Numpy中的特征值无效:每个元素都是一个浮点

Python 计算Numpy中的特征值无效:每个元素都是一个浮点,python,python-2.7,numpy,linear-algebra,Python,Python 2.7,Numpy,Linear Algebra,尝试计算牛顿法优化矩阵的特征值 在PyDev for Eclipse中使用Python 2.7.6 这是PyDev返回的变量(Hessian): ndarray: [[ 0.01 0. ] [ 0. 1. ]] 以下命令: np.linalg.eig(Hessian) 返回异常: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any

尝试计算牛顿法优化矩阵的特征值

在PyDev for Eclipse中使用Python 2.7.6

这是PyDev返回的变量(Hessian):

ndarray: [[ 0.01  0.  ]
[ 0.    1.  ]]
以下命令:

np.linalg.eig(Hessian)
返回异常:

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''
我甚至尝试将每个元素转换为浮点值,方法是循环遍历每个元素并使用
float
函数

编辑/进一步信息:插入
print repr(Hessian)
后产生以下结果

array([[0.01, 0.0],
   [0.0, 1.0]], dtype=object)

从您的评论来看,矩阵似乎不是numpy数组,在使用numpy时会导致错误

正如你所指出的:

“可能是这个过程引起了麻烦。”

我也不能重现你的错误

简单尺度变换矩阵如
[[0.01,0.],[0,1.]
的EIG变换器显然是标准基向量
[1,0]
[0,1]
,通过检查,特征值为0.01和1

相关的numpy模块在执行此操作时没有问题,因此错误一定在别处

>>> import numpy as np
>>> M = np.array([[0.01,0.],[0.,1.]])
>>> M
array([[ 0.01,  0.  ],
       [ 0.  ,  1.  ]])
>>> np.linalg.eig(M)
(array([ 0.01,  1.  ]), array([[ 1.,  0.],
       [ 0.,  1.]]))

你能给我们看看
打印报告(你的_数组)
的回溯和输出吗?很抱歉,我已经解决了。如果我将它设置为Hessian=array(Hessian,dtype=numpy.float32),它现在就可以工作了。我将尝试为其他人做上述工作,以便他们能够了解诊断的具体情况。不幸/幸运的快速修复抱歉…
print repr(Hessian)
output现在插入到上面的底部。听起来问题出在Sympy处理上。号码仍保存为Sympy表达式。是的,很抱歉,我应该提到我在IDLE中重新创建了一个类似的实例,并且它工作正常。问题是,我使用Symphy处理每个元素,以区分函数,从而创建一个Hessian矩阵。可能是这个
Hessian[i,j]=diff(diff(function,x_i),x_j)
的过程造成了这个问题。编辑解决方案以适应上面的信息,我会接受它。谢谢你的信息!