def apmapr(a, a1, a2, b1, b2):
    """Vector linear transformation.

    Map the range of pixel values ``a1, a2`` from ``a``
    into the range ``b1, b2`` into ``b``.
    It is assumed that ``a1 < a2`` and ``b1 < b2``.

    Parameters
    ----------
    a : float
        The value to be mapped.

    a1, a2 : float
        The numbers specifying the input data range.

    b1, b2 : float
        The numbers specifying the output data range.

    Returns
    -------
    b : float
        Mapped value.

    """
    scalar = (b2 - b1) / (a2 - a1)
    return max(b1, min(b2, (a - a1) * scalar + b1))