我正在使用scipy.optimize,并且出现错误消息问题:
TypeError Traceback (most recent call last)
<ipython-input-15-ca9bd28437f1> in <module>()
6 A2 = np.concatenate((A, lmbda * C),axis=0)
7 g2 = np.concatenate((g,np.zeros(len(Files))))
----> 8 f_nnls, rnorm = nnls(A2,g2)
9
TypeError: 'list' object is not callable
代码:
import numpy as np
from scipy.optimize import nnls
#non-negative-least-square solution
lmbda = 0.12
#for random Matrices try:
A = np.random.rand(134,106)
g = np.random.rand(134,)
(x, weight) = np.polynomial.legendre.leggauss(106)
W = np.zeros((106, 106), float)
np.fill_diagonal(W, weight)
C = np.sqrt(W)
A2 = np.concatenate((A, lmbda * C),axis=0)
g2 = np.concatenate((g,np.zeros(106)))
f_nnls, rnorm = nnls(A2,g2) #this line produces the error
A,C和g是定义的numpy数组,这不是维度问题。
我可以在jupyter Notebook中运行一次该程序,但是第二次出现错误消息。我不明白这是什么问题。在绝望中,我将数组更改为列表,但这都不起作用。感谢您的阅读。
链接:https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.nnls.html