def merge_shapes(shape, merged_axis: int, target_axis: int) -> list:
    """
    Merge two axes of a shape into one, removing `merged_axis` and multiplying the size of the `target_axis` by the size
    of the `merged_axis`.

    :param shape: The full shape, tuple or tf.TensorShape.
    :param merged_axis: The index of the axis to remove.
    :param target_axis: The index of the axis to add to.
    :return: A list representing the merged shape.
    """
    shape = list(shape)
    shape[target_axis] *= shape[merged_axis]
    shape.pop(merged_axis)
    return shape