code: def _dtw_path(dtw: CostMatrix) -> np.ndarray:
      i = dtw.n
      j = dtw.m
  
      path = []
  
      while i > 0 or j > 0:
          path.append((i - 1, j - 1))
  
          stencil = [
              (i - 1, j - 1),  # diagonal
              (i - 1, j),  # left
              (i, j - 1),  # down
          ]
  
          costs = [dtw[i, j] for i, j in stencil]
          index_min = costs.index(min(costs))
  
          i, j = stencil[index_min]
  
      path.reverse()
      return np.array(path)
  
imports: import copy
  from typing import Callable, Optional, Union
  import numpy
  import pandas
  import xarray
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not
  from darts.timeseries import DIMS
  from .cost_matrix import CostMatrix
  from .window import CRWindow, NoWindow, Window
label_desc: Use image node_id 2 for calling a global function with example usage: _dtw_path(dtw) and returns: np