code: def _torch_gather(F, data: Tensor, idx: Tensor, axis: int):
      """
      Pytorch-style gather_nd.
      """
      ndim = 4
      if axis < 0:
          axis = ndim + axis
      mx_idx = []
      for dim in range(ndim):
          if dim == axis:
              d_idx = F.broadcast_like(idx, data)
          else:
              d_idx = F.contrib.arange_like(data, axis=dim)
              for _ in range(dim):
                  d_idx = F.expand_dims(data=d_idx, axis=0)
              for _ in range(ndim - dim - 1):
                  d_idx = F.expand_dims(data=d_idx, axis=-1)
              d_idx = F.broadcast_like(d_idx, data)
          mx_idx.append(d_idx)
      mx_idx = F.stack(*mx_idx, axis=0)
      return F.gather_nd(data, mx_idx)
  
imports: import math
  from typing import List, Optional, Tuple
  from mxnet import init
  from mxnet.gluon import HybridBlock, Parameter, nn
  from mxnet.gluon.contrib.nn import HybridConcurrent
  from gluonts.core.component import validated
  from gluonts.mx import Tensor
label_desc: Use image node_id 1 for calling a global function with example usage: _torch_gather(F, data, idx, axis) and returns: F