code: def extract_to(
      array: Tensor, indices: Tensor, num_dim: int
  ) -> Tensor:
      b = indices.shape[0]
      out = array.gather(-1, indices).contiguous()
      return out.view(b, *([1] * (num_dim - 1)))
  
imports: import torch
  from torch import Tensor
  from typing import Union
  from cftool.array import tensor_dict_type
label_desc: Use image node_id 1 for calling a global function with example usage: extract_to(array, indices, num_dim) and returns: out