def im_to_numpy(tensor):
    """Convert a tensor image to a NumPy image.

    The function converts the :math:`K\\times H\\times W` tensor :attr:`tensor`
    to a corresponding :math:`H\\times W\\times K` NumPy array.

    Args:
        tensor (:class:`torch.Tensor`): input tensor.

    Returns:
        :class:`numpy.ndarray`: NumPy array.
    """
    tensor_reshaped = tensor.expand(3, *tensor.shape[1:]).permute(1, 2, 0)
    return tensor_reshaped.detach().cpu().numpy()
