Reputation: 53
I am trying to find the derivative of a function with the scipy derivative module. Unfortunately I cant parse my argument into the function without a TypeError:
def f(x, *arg):
beta = arg
y = -x + beta * np.tanh(x)
return y
param = (0,)
der_x0 = derivative(f, x0 = 0.0, dx = 1e-6, args = param)
Output:
TypeError: 'numpy.float64' object cannot be interpreted as an integer
Upvotes: 2
Views: 122
Reputation: 18695
beta
is of type tuple (try e.g. to add print(beta)
after beta = arg
and you should see something like (0,)
as printout instead of 0
).
Try:
beta = arg[0]
instead, i.e.
def f(x, *arg):
beta = arg[0]
y = -x + beta * np.tanh(x)
return y
and you should get a value of -1.0
for der_x0
.
Upvotes: 1