Integrating with an array of upper limits without sacrificing time efficiency

39 Views Asked by At

I am working on an algorithm to compute some model. Let's say

def model(z):
    return z ** 2

Now, I need to use an array of upper limits to compute an array of values for definite integrals of this function. I.e.

from scipy.integrate import quad
upp_lim = [0, 1, 2, 3, 4]
res_arr = quad(model, 0, upp_lim)

This of course, gives the error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The issue here is that I need to further work on this function by using it in an MCMC model (emcee). Hence, if I use any sort of loop, the MCMC algorithm will take an extremely long time to run, even with multiprocessing.

Is there a method to have the integration function accept an array of upper limits without sacrificing this much time? The quad module is not a necessity, however it is the fastest module I have found.

Existing questions give iteration as an answer. Some pre-existing questions do not iterate over the limits, however still involve some component of iteration. This is out of my question's scope as I am wondering whether an alternative exists.

0

There are 0 best solutions below