[Numpy-discussion] element-wise array segmental function operation?

oyster lepto.python at gmail.com
Mon Mar 23 02:46:27 EDT 2015

Hi, all
I want to know wether there is a terse way to apply a function to
every array element, where the function behaves according to the
element value.
for example
def fun(v):
    if 0<=v<60:
        return f1(v)    #where f1 is a function
    elif 60<=v<70:
        return f2(v)
    elif 70<=v<80:
        return f3(v)
    ...and so on...

for 'a=numpy.array([20,50,75])', I hope to get numpy.array([f1(20),
f1(50), f3(75)])

thanks in advance


More information about the NumPy-Discussion mailing list