code: def transition_loop(
      n_states: int, prob: Union[float, Iterable[float]]
  ) -> np.ndarray:
      """Construct a self-loop transition matrix over ``n_states``.
  
      The transition matrix will have the following properties:
  
          - ``transition[i, i] = p`` for all ``i``
          - ``transition[i, j] = (1 - p) / (n_states - 1)`` for all ``j != i``
  
      This type of transition matrix is appropriate when states tend to be
      locally stable, and there is no additional structure between different
      states.  This is primarily useful for de-noising frame-wise predictions.
  
      Parameters
      ----------
      n_states : int > 1
          The number of states
  
      prob : float in [0, 1] or iterable, length=n_states
          If a scalar, this is the probability of a self-transition.
  
          If a vector of length ``n_states``, ``p[i]`` is the probability of self-transition in state ``i``
  
      Returns
      -------
      transition : np.ndarray [shape=(n_states, n_states)]
          The transition matrix
  
      Examples
      --------
      >>> librosa.sequence.transition_loop(3, 0.5)
      array([[0.5 , 0.25, 0.25],
             [0.25, 0.5 , 0.25],
             [0.25, 0.25, 0.5 ]])
  
      >>> librosa.sequence.transition_loop(3, [0.8, 0.5, 0.25])
      array([[0.8  , 0.1  , 0.1  ],
             [0.25 , 0.5  , 0.25 ],
             [0.375, 0.375, 0.25 ]])
      """
      if not (is_positive_int(n_states) and (n_states > 1)):
          raise ParameterError(
              f"n_states={n_states} must be a positive integer > 1"
          )
  
      transition = np.empty((n_states, n_states), dtype=np.float64)
  
      # if it's a float, make it a vector
      prob = np.asarray(prob, dtype=np.float64)
  
      if prob.ndim == 0:
          prob = np.tile(prob, n_states)
  
      if prob.shape != (n_states,):
          raise ParameterError(
              f"prob={prob} must have length equal to n_states={n_states}"
          )
  
      if np.any(prob < 0) or np.any(prob > 1):
          raise ParameterError(
              f"prob={prob} must have values in the range [0, 1]"
          )
  
      for i, prob_i in enumerate(prob):
          transition[i] = (1.0 - prob_i) / (n_states - 1)
          transition[i, i] = prob_i
  
      return transition
  
imports: from __future__ import annotations
  import numpy
  from scipy.spatial.distance import cdist
  from numba import jit
  from .util import pad_center, fill_off_diagonal, is_positive_int, tiny, expand_to
  from .util.exceptions import ParameterError
  from .filters import get_window
  from typing import Any, Iterable, List, Optional, Tuple, Union, overload
  from typing_extensions import Literal
  from ._typing import _WindowSpec, _IntLike_co
label_desc: Use image node_id 32 for calling a global function with example usage: transition_loop(n_states, prob) and returns: transition