Flip an image either horizontally (left-right mirror) or vertically (top-bottom mirror).
def flip_image(
image: list[list[list[int]]],
direction: str = "horizontal",
) -> list[list[list[int]]]:
"""
image: [H, W, C]
direction: 'horizontal' or 'vertical'
"""
H = len(image)
W = len(image[0])
if direction == "horizontal":
return [row[::-1] for row in image]
elif direction == "vertical":
return image[::-1]
else:
return [row[:] for row in image]