def clip_box(box, shape):
    """
    Clip box for given image shape.

    Args:
        box (array_like[int]): Box for clipping in the next format:
            [y_min, x_min, y_max, x_max].
        shape (tuple[int]): Shape of image.

    Returns:
        array_like[int]: Clipped box.

    """
    ymin, xmin, ymax, xmax = box
    if ymin < 0:
        ymin = 0
    elif ymin >= shape[0]:
        ymin = shape[0] - 1
    box[0] = ymin
    if xmin < 0:
        xmin = 0
    elif xmin >= shape[1]:
        xmin = shape[1] - 1
    box[1] = xmin
    if ymax < 0:
        ymax = 0
    elif ymax >= shape[0]:
        ymax = shape[0] - 1
    box[2] = ymax
    if xmax < 0:
        xmax = 0
    elif xmax >= shape[1]:
        xmax = shape[1] - 1
    box[3] = xmax
    return box