code: def vec_to_sym_matrix(vec, diagonal=None):
      """Return the symmetric matrix given its flattened lower triangular part.
  
      Acts on the last dimension of the array if not 1-dimensional.
      Diagonal can be encompassed in vec or given separately. In both cases, note
      that diagonal elements are multiplied by sqrt(2).
  
      .. versionadded:: 0.3
  
      Parameters
      ----------
      vec : numpy.ndarray or list of numpy arrays, shape \
          (..., n_columns * (n_columns + 1) /2) or
          (..., (n_columns - 1) * n_columns / 2) if diagonal is given separately.
          The input array.
  
      diagonal : numpy.ndarray, shape (..., n_columns), optional
          The diagonal array to be stacked to vec. If None, the diagonal is
          assumed to be included in vec.
  
      Returns
      -------
      sym : numpy.ndarray, shape (..., n_columns, n_columns).
          The output symmetric matrix.
  
      Notes
      -----
      This function is meant to be the inverse of sym_matrix_to_vec. If you have
      discarded the diagonal in sym_matrix_to_vec, you need to provide it
      separately to reconstruct the symmetric matrix. For instance this can be
      useful for correlation matrices for which we know the diagonal is 1.
  
      See Also
      --------
      nilearn.connectome.sym_matrix_to_vec
  
      """
      n = vec.shape[-1]
      # Compute the number of the symmetric matrix columns
      # solve n_columns * (n_columns + 1) / 2 = n subject to n_columns > 0
      n_columns = (sqrt(8 * n + 1) - 1.0) / 2
      if diagonal is not None:
          n_columns += 1
  
      if n_columns > floor(n_columns):
          raise ValueError(
              f"Vector of unsuitable shape {vec.shape} cannot be transformed to "
              "a symmetric matrix."
          )
  
      n_columns = int(n_columns)
      first_shape = vec.shape[:-1]
      if diagonal is not None and (
          diagonal.shape[:-1] != first_shape
          or diagonal.shape[-1] != n_columns
      ):
          raise ValueError(
              f"diagonal of shape {diagonal.shape} incompatible "
              f"with vector of shape {vec.shape}"
          )
  
      sym = np.zeros(first_shape + (n_columns, n_columns))
  
      # Fill lower triangular part
      skip_diagonal = diagonal is not None
      mask = np.tril(
          np.ones((n_columns, n_columns)), k=-skip_diagonal
      ).astype(bool)
      sym[..., mask] = vec
  
      # Fill upper triangular part
      sym.swapaxes(-1, -2)[..., mask] = vec
  
      # (Fill and) rescale diagonal terms
      mask.fill(False)
      np.fill_diagonal(mask, True)
      if diagonal is not None:
          sym[..., mask] = diagonal
  
      sym[..., mask] *= sqrt(2)
  
      return sym
  
imports: import warnings
  from math import floor, sqrt
  import numpy
  from scipy import linalg
  from sklearn.base import BaseEstimator, TransformerMixin, clone
  from sklearn.covariance import LedoitWolf
  from nilearn._utils.docs import fill_doc
  from ..None import signal
  from .._utils.extmath import is_spd
label_desc: Use image node_id 7 for calling a global function with example usage: vec_to_sym_matrix(vec, diagonal) and returns: sym