I am trying to write a function and I want it to return one element when the input is element and an array of outputs if the input is array such that each element of output array is associated with the same place in input array. I am giving a dummy example:
import numpy as np
def f(a):
if a<5:
print a;
f(np.arange(11))
This code returns the error: if a<5:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I expect the output to be:
0
1
2
3
4
How can I make it to work the way I explained as I believe many python functions are working in this way?
Thanks.
if a<5to do?