code: def tucker_mode_dot(
      tucker_tensor, matrix_or_vector, mode, keep_dim=False, copy=False
  ):
      """n-mode product of a Tucker tensor and a matrix or vector at the specified mode
  
      Parameters
      ----------
      tucker_tensor : tl.TuckerTensor or (core, factors)
  
      matrix_or_vector : ndarray
          1D or 2D array of shape ``(J, i_k)`` or ``(i_k, )``
          matrix or vectors to which to n-mode multiply the tensor
      mode : int
  
      Returns
      -------
      TuckerTensor = (core, factors)
          `mode`-mode product of `tensor` by `matrix_or_vector`
          * of shape :math:`(i_1, ..., i_{k-1}, J, i_{k+1}, ..., i_N)` if matrix_or_vector is a matrix
          * of shape :math:`(i_1, ..., i_{k-1}, i_{k+1}, ..., i_N)` if matrix_or_vector is a vector
  
      See also
      --------
      tucker_multi_mode_dot : chaining several mode_dot in one call
      """
      shape, _ = _validate_tucker_tensor(tucker_tensor)
      core, factors = tucker_tensor
      contract = False
  
      if tl.ndim(matrix_or_vector) == 2:  # Tensor times matrix
          # Test for the validity of the operation
          if matrix_or_vector.shape[1] != shape[mode]:
              raise ValueError(
                  f"shapes {shape} and {matrix_or_vector.shape} not aligned in mode-{mode} multiplication: "
                  f"{shape[mode]} (mode = {mode}) != {matrix_or_vector.shape[1]} (dim 1 of matrix)"
              )
  
      elif tl.ndim(matrix_or_vector) == 1:  # Tensor times vector
          if matrix_or_vector.shape[0] != shape[mode]:
              raise ValueError(
                  f"shapes {shape} and {matrix_or_vector.shape} not aligned for mode-{mode} multiplication: "
                  f"{shape[mode]} (mode = {mode}) != {matrix_or_vector.shape[0]} (vector size)"
              )
          if not keep_dim:
              contract = True  # Contract over that mode
      else:
          raise ValueError(
              "Can only take n_mode_product with a vector or a matrix."
          )
  
      if copy:
          factors = [tl.copy(f) for f in factors]
          core = tl.copy(core)
  
      if contract:
          print("contracting mode")
          f = factors.pop(mode)
          core = mode_dot(core, tl.dot(matrix_or_vector, f), mode=mode)
      else:
          factors[mode] = tl.dot(matrix_or_vector, factors[mode])
  
      return TuckerTensor((core, factors))
  
imports: from ._factorized_tensor import FactorizedTensor
  from .base import unfold, tensor_to_vec
  from .tenalg import multi_mode_dot, mode_dot
  from .None import backend
  import numpy
  from scipy.optimize import brentq
  import warnings
label_desc: Use image node_id 6 for calling a global function with example usage: tucker_mode_dot(tucker_tensor, matrix_or_vector, mode, keep_dim, copy) and returns: TuckerTensor