xxxxxxxxxx
def myfunc(a, b):
"Return a-b if a>b, otherwise return a+b"
if a > b:
return a - b
else:
return a + b
xxxxxxxxxx
import numpy as np
def myfunc(a):
# Return True if a>b, otherwise False"
if a > 2:
return bool(True)
else: return bool(False)
vfunc = np.vectorize(myfunc) # vectorize iterates function.
vfunc([1, 2, 3, 4])
# array([False, False, True, True])
xxxxxxxxxx
>>> vfunc = np.vectorize(myfunc)
>>> vfunc([1, 2, 3, 4], 2)
array([3, 4, 1, 2])