So lets say I've got a variable a which is a numpy array. When a is less than a certain value I want to apply a certain function, and when it is greater than this value I would apply a different function.
I've tried doing this with a boolean if statement but return the following error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I know from this answer that I need to use numpy a.any() and a.all() but I'm unclear how/where I would use them in the loop. I've provided a really simple example below:
import numpy as np
a = np.linspace(1, 10, num=9)
def sortfoo(a):
if a < 5:
b = a*3
else:
b = a/2
return b
result = sortfoo(a)
print(result)
So I guess I'm asking for an example of where and how I need to use any() and all() to the above.
Really basic question but for some reason my brain isn't working clearly. Any help much appreciated.