我正在scipy模块中使用minimize()函数研究出租车距离。这是Ipython Notebook Essentials'中的源代码。
import numpy as np
import matplotib.pyplot as plt
import pandas as pd
import scipy.optimize
points = np.array([[10.3, 15.4], [6.5, 8.8], [15.6, 10.3], [4.7, 12.8]])
def make_txmin(points):
def txmin_func(p):
return sum(np.abs(points - p))
return txmin_func
txmin = make_txmin(points)
x0 = np.array([0., 0.])
res = scipy.optimize.minimize(txmin, x0 , method='nelder-mead',options={'xtol': 1e-5, 'disp':True})
我运行此源代码,然后出现这样的错误;
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/IPython/chapter4/taxicab distance.py", line 15, in <module>
res = scipy.optimize.minimize(txmin, x0 , method='nelder-mead',options={'xtol': 1e-5, 'disp':True})
File "C:\Users\user\Anaconda3\lib\site-packages\scipy\optimize\_minimize.py", line 435, in minimize
return _minimize_neldermead(fun, x0, args, callback, **options)
File "C:\Users\user\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 439, in _minimize_neldermead
fsim[0] = func(x0)
ValueError: setting an array element with a sequence.
Process finished with exit code 1
请告诉我此代码中的问题是什么,我该怎么做。