code: def reshape_channel_complex_to_last_dim(x: Tensor) -> Tensor:
      """
      Swaps the complex dimension with the channel dimension so that the network output has 2 as its last dimension
  
      Args:
          x: input of shape (B,C*2,H,W) for 2D data or (B,C*2,H,W,D) for 3D data
  
      Returns:
          output of shape (B,C,H,W,2) for 2D data or (B,C,H,W,D,2) for 3D data
      """
      if x.shape[1] % 2 != 0:
          raise ValueError(
              f"channel dimension should be even but ({x.shape[1]}) is odd."
          )
  
      if len(x.shape) == 4:  # this is 2D
          b, c2, h, w = x.shape  # c2 means c*2
          c = c2 // 2
          return x.view(b, 2, c, h, w).permute(0, 2, 3, 4, 1)
  
      elif len(x.shape) == 5:  # this is 3D
          b, c2, h, w, d = x.shape  # c2 means c*2
          c = c2 // 2
          return x.view(b, 2, c, h, w, d).permute(0, 2, 3, 4, 5, 1)
  
      else:
          raise ValueError(
              f"only 2D (B,C*2,H,W) and 3D (B,C*2,H,W,D) data are supported but x has shape {x.shape}"
          )
  
file_path: MONAI/monai/apps/reconstruction/networks/nets/utils.py
imports: from __future__ import annotations
  import math
  from torch import Tensor
  from torch.nn import functional
  from monai.apps.reconstruction.complex_utils import complex_conj_t, complex_mul_t
  from monai.networks.blocks.fft_utils_t import fftn_centered_t, ifftn_centered_t
label_desc: Use image node_id 2 for calling a global function with example usage: reshape_channel_complex_to_last_dim(x) and returns: x, x