code: def ReverseSequence(a, seq_lengths, seq_dim, batch_dim):
      
      r = np.copy(a)
      invidxs = (len(r.shape) - 1) * [slice(None)]
      if seq_dim < batch_dim:
          invidxs[seq_dim] = slice(None, None, -1)
      else:
          invidxs[seq_dim - 1] = slice(None, None, -1)
      _invidxs = tuple(invidxs)
      selidxs = len(r.shape) * [slice(None)]
      for i, l in enumerate(seq_lengths):
          if not l:
              continue
          selidxs[batch_dim] = i
          selidxs[seq_dim] = slice(0, l)
          _selidxs = tuple(selidxs)
          r[_selidxs] = a[_selidxs][_invidxs]
      return r,
docs: Sequential reverse op.