我正在尝试使用fmin来缩小我的功能,你可以找到我的函数下面的例子,有一个类:
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import sys,os
import numpy as np
from math import exp
import scipy
from scipy.optimize import fmin
from carlo import *
A=real()
x_r=0.11245
x_i=0.14587
C=A.minim([x_r,x_i])
part_real=0.532
part_imag=1.2
R_0 = fmin(C,[part_real,part_imag])
这是我的班级:(名称carlo.py)
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import sys,os
import numpy as np
import random, math
import matplotlib.pyplot as plt
import cmath
#pdb.set_trace()
class real:
def __init__(self):
self.nmodes = 4
self.L_ch = 1
self.w = 2
def minim(self,p):
x_r=p[0]
x_i=p[1]
self.a=complex(3,4)*(3*np.exp(1j*self.L_ch))
self.T=np.array([[0.0,2.0*self.a],[(0.00645+(x_r)**2), 4.3*x_i**2]])
self.Id=np.array([[1,0],[0,1]])
self.disp=np.linalg.det(self.T-self.Id)
return self.disp
我有这个错误:
File "/usr/local/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 281, in function_wrapper
return function(*(wrapper_args + args))
TypeError: 'numpy.complex128' object is not callable
我尝试使用它,但我不理解这个错误,如果我只返回T我有错误:TypeError:'numpy.ndarray'对象不可调用。请帮助我,谢谢你的回答。