Suppose I have the following simple function and inputs:
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)
I would like to solve this function for a that minimizes the output (maximizes e).
scipy.optimize.fmin(test_func,a1,args=(b1))
But this throws a type error
TypeError: test_func() takes 2 positional arguments but 4 were given
My quesiton is i) is this a good way to solve for the max of such a function and ii) what the devil is the problem?
You are missing a comma after the b1
in the extra argument:
scipy.optimize.fmin(test_func,a1,args=(b1,))
seems to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.