I'm defining a function by intervals. And when python compares the parameter fck
to a delimiting value between 2 intervals (fck<50
) it returns an error. I understand that it can't compare an array to an integer, but fck
isn't an array! It's a parameter that I intend to be a float. How does python decide what type the parameter has and how can I define it?
In other similar functions, I've defined, everything's fine. I'm including the problematic function and an example of a working one. I can't see any differences between them. What is the problem? I don't only want to make it work, but I also want to understand what python is doing.
I've tried stating the parameter's type by doing def par_rec(eps,fck:float):
and it doesn't change the outcome.
The definition that returns an error on it's second line:
def par_rec(eps,fck):
if fck<50:
eps0=0.002
else:
eps0=0.002+0.000085*(fck-50)**0.5
if fck<50:
epsu=0.0035
else:
epsu=0.0026+0.0144*((100-fck)/100)**4
if fck<50:
n=2
else:
n=1.4+9.6*((100-fck)/100)**4
if eps<0:
sig=0
elif eps<eps0:
sig=fck/1.5*(1-(1-eps/eps0)**n)
else:
sig=fck/1.5
return sig
And a similar definition that doesn't cause any problems:
def fctm(fck):
if fck<50:
fctm = 0.3 * fck ** (2 / 3)
else:
fctm=0.58*fck**0.5
return fctm
I'm defining the function, I'm not calling it, when I get an error:
line 81, in par_rec
if fck<50:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()