I am recieving the error seen in the question title when attempting to run my code which attempts to perform some math and will later desire to plot some conditional functions.
My code is as follows
import math
import numpy as np
def f(λ,a,u,o1,o2):
o = o1 if (λ <= u) else o2
return a*math.exp((λ-u)^2/(-2*o^2))
x_lamda = np.arange(4000,8000,10)
Yx1 = f(x_lamda,1.056,5998,379,310)
As seen my function is f of λ which is a gaussian with a piecewise function for o which changes depending on if λ is below or above the mean (u). I can't seem to find anything online to fix this error in a particular case like this. How do you avoid this 'ambiguity' when making conditional expressions?
This is the output:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
What I have tried:
I have attempted to use the a.any and the a.all functions on the "λ <= u" part in particular but I am running into more errors.
I will also like to mention that I will be using the quad function later to find definite intergrals plus I will be attempting to plot these later. Will I be running into similar problems later? Will this call for a new approach?