Let\'s say we have a particularly simple function like
import scipy as sp def func(x, y): return x + y
This function evidently works for
For this special case, you could also write a function that operates on both, NumPy arrays and plain Python floats:
def func2d(x, y): z = 2.0 * (x > y) - 1.0 z *= y return x + z
This version is also more than four times as fast as unutbu's func2a() (tested with N = 100).
N = 100