def linterp(x0, y0, x1, y1, x, bound=False):
    """
    Linear interpolation

    :param x0: Input value at one end of line
    :param y0: Output value which x0 maps onto
    :param x1: Input value at other end of line
    :param y1: Output value which x1 maps onto
    :param x:  Input value(s)
    :param bound: If True, return the correct y endpoint value if x is outside the x endpoints
    :return:   Output value(s).

    Note: All and only operators +,-,*, and / are used. Any type which supports
          these may be used as parameters, including numpy arrays. In case arrays
          are used, all broadcasting is supported and inputs must be compatible
          by broadcasting.

          The usual case is for x0,y0,x1,y1 to all be scalar and for x to be
          either scalar or array, in which case the output will be the same size
          and shape as the input x.

          If bound= is set, this uses < and > and therefore only works for types which can
          be compared, so scalars, not numpy arrays.
    """
    if bound:
        if x<x0:
            return y0
        if x>x1:
            return y1
    t = (x - x0) / (x1 - x0)
    return (1 - t) * y0 + t * y1