I am trying to do a fit to a given function using Scipy. Scipy.optimize.leastsq needs a vectorized function as one of the input parameters. This all works fine, but now I have a more complicated function which is not vectorized automatically by Scipy/Numpy.
def f1(a, parameters):
b, c = parameters
result = scipy.integrate.quad(integrand, lower, upper, (a, b, c))
return result
or to give a closed example numpy.vectorize also does not work with
def f2(a, parameters):
b, c = parameters
return a+b+c
Is there a possibility to vectorize these functions in Scipy/Numpy?
Thank you for any help! Alexander
Sorry, I'm not sure what the question is. Python *args collects any number of args,
which a function can unpack as it pleases; see
docs.python.org/tutorial/...
import numpy as np
from scipy.integrate import quad
def f2( a, *args ):
print "args:", args
return a + np.sum( args, axis=0 )
x = np.ones(3)
print f2( x, x*2, x*3 )
def quadf( *args ):
print "quadf args:", args
return 1
quad( quadf, 0, 1, (2,3) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With