我想使用python优化工具,这里是我编写的代码: 导入numpy为np 来自scipy.optimize import最小化
h = np.ones((2,2,2))
P_ULmax = 1e2;
def objective(y):
temp = 0
for b in range(2):
for m in range(2):
for n in range(2):
interference = 1
for b_p in range(2):
for m_p in range(2):
if b_p != b and m_p != m:
interference = interference + y[b_p,m_p,n]*h[b,m_p,n]*P_ULmax
temp = temp + y[b,m,n]*h[b,m,n]*P_ULmax/interference
return -temp
#x0 = np.zeros(4)
x0 = np.ones((2,2,2))
print(objective(x0))
b = (0.0,1.0)
#bnds = ([b,b],[b,b])
bnds = ((0.0, 1.0))*len(x0.flatten())
bnds = np.reshape(bnds, (8,2))
#bnds = bnds.flatten()
sol = minimize(objective,x0,method='SLSQP',\
bounds=bnds)
但是在跑步之后,它说你的目标函数必须是标量。问题是什么? 非常感谢