我定义了一个引用数组并在该数组中广播变量的函数。当函数运行时,它工作正常。但是,当我尝试使用 scipy.minimize 来最小化函数时,我收到以下错误:
操作数不能与形状一起广播 (75,) (2,)
任何帮助将非常感激!
import numpy as np
from scipy.optimize import minimize
a = [2, 4, 6, 5, 2]
b = 3
c = 4
def mult(x):
target = np.array(np.array(a) * x) + x
mean = np.mean(target)
sd = np.std(target)
mean_ch = np.abs(mean / b - 1)
sd_ch = np.abs(sd / c - 1)
total_ch = mean_ch + sd_ch
return total_ch
x0 = [2, 4]
minimize(mult, x0)