【发布时间】:2014-04-18 01:56:44
【问题描述】:
我正在将此 matlab 函数句柄转换为 python 并在 python 中收到此错误(ValueError: setting an array element with a sequence.)。如果有明显的错误,我对python很抱歉。
在matlab中:
P = [1 1; 6 1; 6 5]
fh = @(x) sqrt(sum((ones(3,1)*x - P).^2, 2))
[x,fval] = fminsearch(@(x) max(fh(x)),[0 0])
在python中:
P = np.matrix([[1, 1],[ 6, 1],[ 6, 5]])
fh = lambda x:np.sqrt(sum(np.power((np.ones((3,1))*x - P),2),axis = 0))
xopt = scipy.optimize.fmin(func=fh,x0 = np.matrix([0, 0]))
该代码在 matlab 中有效,但在 python 中无效。
【问题讨论】: