Search code examples
pythonscipynumerical-integration

Integration with upper boundary as independent variable


I am trying to define a function with the independent variable as upper boundary of the integral:

from scipy import integrate

def integr(x):
    f = lambda y: 1 #example function
    value,_ = integrate.quad(f, 0, x)
    return value

Evaluating integr for a single number works. However, if I want to apply it to an array to receive a result array, a Value error is returned:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Do you know a solution for this? Do I need to make a loop over the values of the input array?

Thanks a lot in advance!


Solution

  • I just found the answer in another post.

    x = np.linspace(0, 100) #example array
    list(map(integr, x)))
    

    Sorry for asking such simple questions, but I'm new with Python.