def shift_and_scale(matrix, shift, scale):
    """ Shift and scale matrix so its minimum value is placed at `shift` and
    its maximum value is scaled to `scale` """

    zeroed = matrix - matrix.min()
    scaled = (scale - shift) * (zeroed / zeroed.max())
    return scaled + shift
Shift and scale matrix so its minimum value is placed at `shift` and
    its maximum value is scaled to `scale`