![]() | Simplest remedy: use NumPy's vectorize class to allow
array arguments to a function:
>>> somefuncv = vectorize(somefunc, otypes='d') >>> # test: >>> x = linspace(-1, 1, 3); print x [-1. 0. 1.] >>> somefuncv(x) array([ 0. , 0. , 0.84147098])Note: The data type must be specified as a character ('d' for double) |
![]() | The speed of somefuncv is unfortunately quite slow |
![]() | A better solution, using where:
def somefuncv2(x): x2 = sin(x) return where(x < 0, 0, x2) |