code: def subspace(
      T,
      m,
      subseq_idx,
      nn_idx,
      k,
      include=None,
      discords=False,
      discretize_func=None,
      n_bit=8,
      normalize=True,
      p=2.0,
      T_subseq_isconstant=None,
  ):
      """
      Compute the k-dimensional matrix profile subspace for a given subsequence index and
      its nearest neighbor index
  
      Parameters
      ----------
      T : numpy.ndarray
          The time series or sequence for which the multi-dimensional matrix profile,
          multi-dimensional matrix profile indices were computed
  
      m : int
          Window size
  
      subseq_idx : int
          The subsequence index in T
  
      nn_idx : int
          The nearest neighbor index in T
  
      k : int
          The subset number of dimensions out of `D = T.shape[0]`-dimensions to return
          the subspace for. Note that zero-based indexing is used.
  
      include : numpy.ndarray, default None
          A list of (zero-based) indices corresponding to the dimensions in `T` that
          must be included in the constrained multidimensional motif search.
          For more information, see Section IV D in:
  
          `DOI: 10.1109/ICDM.2017.66 \
          <https://www.cs.ucr.edu/~eamonn/Motif_Discovery_ICDM.pdf>`__
  
      discords : bool, default False
          When set to `True`, this reverses the distance profile to favor discords rather
          than motifs. Note that indices in `include` are still maintained and respected.
  
      discretize_func : func, default None
          A function for discretizing each input array. When this is `None`, an
          appropriate discretization function (based on the `normalize` parameter) will
          be applied.
  
      n_bit : int, default 8
          The number of bits used for discretization. For more information on an
          appropriate value, see Figure 4 in:
  
          `DOI: 10.1109/ICDM.2016.0069 \
          <https://www.cs.ucr.edu/~eamonn/PID4481999_Matrix%20Profile_III.pdf>`__
  
          and Figure 2 in:
  
          `DOI: 10.1109/ICDM.2011.54 \
          <https://www.cs.ucr.edu/~eamonn/ICDM_mdl.pdf>`__
  
      normalize : bool, default True
          When set to `True`, this z-normalizes subsequences prior to computing distances.
          Otherwise, this function gets re-routed to its complementary non-normalized
          equivalent set in the `@core.non_normalized` function decorator.
  
      p : float, default 2.0
          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. This parameter is ignored when
          `normalize == True`.
  
      T_subseq_isconstant : numpy.ndarray, function, or list, default None
          A parameter that is used to show whether a subsequence of a time series in `T`
          is constant (True) or not. T_subseq_isconstant can be a 2D boolean numpy.ndarry
          or a function that can be applied to each time series in `T`. Alternatively, for
          maximum flexibility, a list (with length equal to the total number of time
          series) may also be used. In this case, T_subseq_isconstant[i] corresponds to
          the i-th time series T[i] and each element in the list can either be a 1D
          boolean np.ndarray, a function, or None.
  
      Returns
      -------
      S : numpy.ndarray
          An array that contains the (singular) `k`th-dimensional subspace for the
          subsequence with index equal to `subseq_idx`. Note that `k+1` rows will be
          returned.
  
      See Also
      --------
      stumpy.mstump : Compute the multi-dimensional z-normalized matrix profile
      stumpy.mstumped : Compute the multi-dimensional z-normalized matrix profile with
          a distributed dask cluster
      stumpy.mdl : Compute the number of bits needed to compress one array with another
          using the minimum description length (MDL)
  
      Examples
      --------
      >>> import stumpy
      >>> import numpy as np
      >>> mps, indices = stumpy.mstump(
      ...     np.array([[584., -11., 23., 79., 1001., 0., -19.],
      ...               [  1.,   2.,  4.,  8.,   16., 0.,  32.]]),
      ...     m=3)
      >>> motifs_idx = np.argsort(mps, axis=1)[:, :2]
      >>> k = 1
      >>> stumpy.subspace(
      ...     np.array([[584., -11., 23., 79., 1001., 0., -19.],
      ...               [  1.,   2.,  4.,  8.,   16., 0.,  32.]]),
      ...     m=3,
      ...     subseq_idx=motifs_idx[k][0],
      ...     nn_idx=indices[k][motifs_idx[k][0]],
      ...     k=k)
      array([0, 1])
      """
      T = core._preprocess(T)
      core.check_window_size(m, max_size=T.shape[-1])
      T_subseq_isconstant = core.process_isconstant(
          T, m, T_subseq_isconstant
      )
  
      if discretize_func is None:
          bins = _inverse_norm(n_bit)
          discretize_func = partial(_discretize, bins=bins)
  
      subseqs, _, _, _ = core.preprocess(
          T[:, subseq_idx : subseq_idx + m], m
      )
      subseqs = core.z_norm(subseqs, axis=1)
      subseqs[T_subseq_isconstant[:, subseq_idx]] = 0.0
  
      neighbors, _, _, _ = core.preprocess(T[:, nn_idx : nn_idx + m], m)
      neighbors = core.z_norm(neighbors, axis=1)
      neighbors[T_subseq_isconstant[:, nn_idx]] = 0.0
  
      disc_subseqs = discretize_func(subseqs)
      disc_neighbors = discretize_func(neighbors)
  
      D = np.linalg.norm(disc_subseqs - disc_neighbors, axis=1)
  
      S = core._subspace(D, k, include=include, discords=discords)
  
      return S
  
file_path: stumpy/stumpy/mstump.py
imports: from functools import lru_cache, partial
  import numpy
  from numba import njit, prange
  from scipy.stats import norm
  from .None import config, core
  from .maamp import maamp, maamp_mdl, maamp_multi_distance_profile, maamp_subspace
label_desc: Use image node_id 2 for calling a global function with example usage: subspace(T, m, subseq_idx, nn_idx, k, include, discords, discretize_func, n_bit, normalize, p, T_subseq_isconstant) and returns: S