15,936,122 members

See more:
, +

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

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:

**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?

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()

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?

Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900

How you fix it depends on what you are trying to do. Maybe you need to put a loop around calling the function and pass it scalars.