def nonanalytical_func(x, a, b):
    """
    This can be any pythonic function which should be fitted, typically one
    which is not easily written or supported as an analytical expression.
    """
    # Do your non-trivial magic here. In this case a Piecewise, although this
    # could also be done symbolically.
    y = np.zeros_like(x)
    y[x > b] = (a * (x - b) + b)[x > b]
    y[x <= b] = b
    return y
def nonanalytical_func ( x , a , b ) : y = np . zeros_like ( x ) y [ x > b ] = ( a * ( x - b ) + b ) [ x > b ] y [ x <= b ] = b return y
This can be any pythonic function which should be fitted, typically one
    which is not easily written or supported as an analytical expression.