code: def _aamp_across_series_nearest_neighbors(
      Ts, Ts_idx, subseq_idx, m, Ts_subseq_isfinite, p
  ):
      """
      For multiple time series find, per individual time series, the subsequences closest
      to a given query.
  
      Parameters
      ----------
      Ts : list
          A list of time series for which to find the nearest neighbor subsequences that
          are closest to the query subsequence `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
  
      Ts_idx : int
          The index of time series in `Ts` which contains the query subsequence
  
      subseq_idx : int
          The subsequence index in the time series `Ts[Ts_idx]` that contains the query
          subsequence
  
      m : int
          Window size
  
      Ts_subseq_isfinite : list
          A list of rolling window `T_subseq_isfinite` for each time series in `Ts`
  
      p : float
          The p-norm to apply for computing the Minkowski distance. Minkowski distance is
          typically used with `p` being 1 or 2, which correspond to the Manhattan distance
          and the Euclidean distance, respectively.
  
      Returns
      -------
      nns_radii : numpy.ndarray
          Radii to subsequences in each time series of `Ts` that are closest to the
          query subsequence `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
  
      nns_subseq_idx : numpy.ndarray
          Indices to subsequences in each time series of `Ts` that are closest to the
          query subsequence `Ts[Ts_idx][subseq_idx : subseq_idx + m]`
      """
      k = len(Ts)
      Q = Ts[Ts_idx][subseq_idx : subseq_idx + m]
      nns_radii = np.zeros(k, dtype=np.float64)
      nns_subseq_idx = np.zeros(k, dtype=np.int64)
  
      for i in range(k):
          if np.any(~np.isfinite(Q)):  # pragma: no cover
              distance_profile = np.full(
                  Ts[i].shape[0] - m + 1, np.inf, dtype=np.float64
              )
          else:
              distance_profile = core.mass_absolute(
                  Q, Ts[i], Ts_subseq_isfinite[i], p=p
              )
  
          nns_subseq_idx[i] = np.argmin(distance_profile)
          nns_radii[i] = distance_profile[nns_subseq_idx[i]]
  
      return nns_radii, nns_subseq_idx
  
file_path: stumpy/stumpy/aamp_ostinato.py
imports: import numpy
  from .None import core
  from .aamp import aamp
  from .aamped import aamped
label_desc: Use image node_id 1 for calling a global function with example usage: _aamp_across_series_nearest_neighbors(Ts, Ts_idx, subseq_idx, m, Ts_subseq_isfinite, p) and returns: nns_radii,  nns_subseq_idx