When using the numpy module on python I'm used to define functions and then apply them on arrays. For example
import numpy as np
def function(x):
return x+1
sample = function(np.random.uniform(0, 1, size=100))
print(sample)
The thing is that if the defined function uses a while loop on its definition it will no longer be able to be applied on an array. For example
import numpy as np
def truncation(x):
i=0
while x > i/3:
i += 1
else:
y = i/3
return y
sample = truncation(np.random.uniform(0, 1, size=100))
print(sample)
would get the error: "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()".
I'm very noob, so any sort of help would be really appreciated.