Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vectorize scipy.integrate.quad

I am using scipy.integrate.quad(f, a, b, args=(c,)) to integrate function f between a and b, adding another parameter c. You can think about f as

f = lambda x, y: x*y 

As I understand it, the function requires a, b, c to be float values. However, I have many integrals to solve, all with the same function, just over vectors of a, b, and c. Iterating through all the vectors is quite inefficient. Is there any way to speed up / vectorize this operation?

like image 765
FooBar Avatar asked Nov 14 '25 12:11

FooBar


1 Answers

Alas, this is not supported by integrate.quad.

You might find better luck with using gaussian quadratures yourself: scipy.integra.fixed_quad chokes on array_like input, but the lower-level routines which compute roots and weights should work. See "Roots and weights for orthogonal polynomials" section here. YMMV though.

like image 58
ev-br Avatar answered Nov 17 '25 09:11

ev-br



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!