【发布时间】:2017-09-26 23:14:34
【问题描述】:
假设我有以下简单的函数和输入:
dates = pd.date_range('20170101',periods=20)
a1 = np.ones(3)
b1 = pd.DataFrame(np.random.randint(10,size=(20,3)),index=dates,columns=['foo','bar','see'])
def test_func(a,b):
c = (a*b).sum(axis=1)
d = c.std()*np.sqrt(3)
e = c.mean()/d
return -np.array(e)
我想解决这个函数来最小化输出(最大化 e)。
scipy.optimize.fmin(test_func,a1,args=(b1))
但这会引发类型错误
TypeError: test_func() takes 2 positional arguments but 4 were given
我的问题是 i)这是解决此类函数最大值的好方法,以及 ii)问题出在哪里?
【问题讨论】:
-
第二部分很清楚。你在滥用 test_func。检查here。您正在提供额外的输入
标签: python function pandas optimization scipy