<div dir="ltr">You can do:<div><br></div><div>vfun = np.vectorize(fun)</div><div>vfun([20,50,75])</div><div><br></div><div>that should work, note the abundant options available for denoting the vectorized arrays in "vectorize". </div><div>Otherwise you could do nested where calls.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-23 7:46 GMT+01:00 oyster <span dir="ltr"><<a href="mailto:lepto.python@gmail.com" target="_blank">lepto.python@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, all<br>
I want to know wether there is a terse way to apply a function to<br>
every array element, where the function behaves according to the<br>
element value.<br>
for example<br>
[code]<br>
def fun(v):<br>
    if 0<=v<60:<br>
        return f1(v)    #where f1 is a function<br>
    elif 60<=v<70:<br>
        return f2(v)<br>
    elif 70<=v<80:<br>
        return f3(v)<br>
    ...and so on...<br>
[/code]<br>
<br>
for 'a=numpy.array([20,50,75])', I hope to get numpy.array([f1(20),<br>
f1(50), f3(75)])<br>
<br>
thanks in advance<br>
<br>
Lee<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Kind regards Nick</div></div></div>
</div>