let's say that I have this function
def funtion(x, bb, aa):
if x>aa:
res = aa
else:
xxr = x/aa
res = bb*(1.5*xxr-0.5*xxr**3)
return res
If I do:
xx = np.linspace(0,49,50)
yy = funct(xx,74,33)
I get the following error:
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The usage of a.any() or a.all() does not solve the problem. The results is different from what I am looking for.
The usage of a.any() or a.all() leads to
array([ 0. , 3.36260678, 6.71903609, 10.06311044, 13.38865236,
16.68948438, 19.959429 , 23.19230876, 26.38194618, 29.52216379,
32.60678409, 35.62962963, 38.58452292, 41.46528647, 44.26574283,
46.9797145 , 49.60102401, 52.12349389, 54.54094666, 56.84720483,
59.03609094, 61.1014275 , 63.03703704, 64.83674208, 66.49436514,
68.00372875, 69.35865542, 70.55296769, 71.58048808, 72.4350391 ,
73.11044328, 73.60052314, 73.8991012 , 74. , 73.89704205,
73.58404987, 73.05484598, 72.30325291, 71.32309319, 70.10818933,
68.65236386, 66.9494393 , 64.99323817, 62.77758299, 60.2962963 ,
57.5432006 , 54.51211843, 51.1968723 , 47.59128475, 43.68917828])
but this is what I expect
array([ 0. , 3.36260678, 6.71903609, 10.06311044, 13.38865236,
16.68948438, 19.959429 , 23.19230876, 26.38194618, 29.52216379,
32.60678409, 35.62962963, 38.58452292, 41.46528647, 44.26574283,
46.9797145 , 49.60102401, 52.12349389, 54.54094666, 56.84720483,
59.03609094, 61.1014275 , 63.03703704, 64.83674208, 66.49436514,
68.00372875, 69.35865542, 70.55296769, 71.58048808, 72.4350391 ,
73.11044328, 73.60052314, 73.8991012 , 74. , 33. ,
33. , 33. , 33. , 33. , 33. ,
33. , 33. , 33. , 33. , 33. ,
33. , 33. , 33. , 33. , 33. ])
As you can notice, there is a constant value for x>aa, according to the function definition. Maybe I have to re-rewrite the if statement in another way.
Could someone give a glue? It is not possible for me to do a for cycle due to the fact that I need to use the function in another function. Thanks for any kind of help.