How can I vectorize a function in numpy with multiple arguments?

I am trying to bind to a given function using Scipy. Scipy.optimize.leastsq needs a vector function as one of the input parameters. All this works fine, but now I have a more complex function that is not automatically Scipy / Numpy vectorized.

def f1(a, parameters):
    b, c = parameters
    result = scipy.integrate.quad(integrand, lower, upper, (a, b, c))
    return result

or give a private example numpy.vectorize also does not work with

def f2(a, parameters):
    b, c = parameters
    return a+b+c

Is it possible to vectorize these functions in Scipy / Numpy?

Thanks for any help! Alexander

+3
source share
1 answer

, , . Python *args , , ; 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) )
+2

Source: https://habr.com/ru/post/1757427/


All Articles