0
今天我想问你下一个问题 - 如何改变优化函数(scipy,Python)中的x数组?如何在优化函数(scipy,Python)中更改x数组?
实施例:
from scipy.optimize import minimize
def function(x):
for i in range(len(x)):
if x[i]<0:
x[i]=0
F = 0.0
print list(x)
for i in x:
F += i**3
return F
n = 5
x0=[]
for i in range(n):
x0.append(-1.0)
res = minimize(function, x0, method='Nelder-Mead')
print res
但结果是阵列([ - 1,-1,-1,-1,-1。。。]):
.........................
.........................
[0.0, 0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0, 0.0]
[0.0, 0.0, 0.0, 0.0, 0.0]
status: 1
nfev: 1006
success: False
fun: 0.0
x: array([-1., -1., -1., -1., -1.])
message: 'Maximum number of function evaluations has been exceeded.'
nit: 148