code: def parafac2_to_vec(parafac2_tensor):
      r"""Construct a vectorized tensor from a PARAFAC2 decomposition. Uneven slices are padded by zeros.
  
      The decomposition is on the form :math:`(A [B_i] C)` such that the i-th frontal slice,
      :math:`X_i`, of :math:`X` is given by
  
      .. math::
  
          X_i = B_i diag(a_i) C^T,
  
      where :math:`diag(a_i)` is the diagonal matrix whose nonzero entries are equal to
      the :math:`i`-th row of the :math:`I \times R` factor matrix :math:`A`, :math:`B_i`
      is a :math:`J_i \times R` factor matrix such that the cross product matrix :math:`B_{i_1}^T B_{i_1}`
      is constant for all :math:`i`, and :math:`C` is a :math:`K \times R` factor matrix.
      To compute this decomposition, we reformulate the expression for :math:`B_i` such that
  
      .. math::
  
          B_i = P_i B,
  
      where :math:`P_i` is a :math:`J_i \times R` orthogonal matrix and :math:`B` is a
      :math:`R \times R` matrix.
  
      An alternative formulation of the PARAFAC2 decomposition is that the tensor element
      :math:`X_{ijk}` is given by
  
      .. math::
  
          X_{ijk} = \sum_{r=1}^R A_{ir} B_{ijr} C_{kr},
  
      with the same constraints hold for :math:`B_i` as above.
  
      Parameters
      ----------
      parafac2_tensor : Parafac2Tensor - (weight, factors, projection_matrices)
          * weights : 1D array of shape (rank, )
              weights of the factors
          * factors : List of factors of the PARAFAC2 decomposition
              Contains the matrices :math:`A`, :math:`B` and :math:`C` described above
          * projection_matrices : List of projection matrices used to create evolving
              factors.
  
      Returns
      -------
      ndarray
          Full constructed tensor. Uneven slices are padded with zeros.
      """
      return tensor_to_vec(parafac2_to_tensor(parafac2_tensor))
  
imports: from .None import backend
  from .base import unfold, tensor_to_vec
  from ._factorized_tensor import FactorizedTensor
label_desc: Use image node_id 8 for calling a global function with example usage: parafac2_to_vec(parafac2_tensor) and returns: tensor_to_vec