code: def parafac2_normalise(parafac2_tensor):
      """Returns parafac2_tensor with factors normalised to unit length
  
      Turns ``factors = [|U_1, ... U_n|]`` into ``[weights; |V_1, ... V_n|]``,
      where the columns of each `V_k` are normalized to unit Euclidean length
      from the columns of `U_k` with the normalizing constants absorbed into
      `weights`. In the special case of a symmetric tensor, `weights` holds the
      eigenvalues of the tensor.
  
      Parameters
      ----------
      parafac2_tensor : Parafac2Tensor = (weight, factors, projections)
          factors is list of matrices, all with the same number of columns
          i.e.::
              for u in U:
                  u[i].shape == (s_i, R)
  
          where `R` is fixed while `s_i` can vary with `i`
  
      Returns
      -------
      Parafac2Tensor = (normalisation_weights, normalised_factors, normalised_projections)
      """
      # allocate variables for weights, and normalized factors
      _, rank = _validate_parafac2_tensor(parafac2_tensor)
      weights, factors, projections = parafac2_tensor
  
      # if (not copy) and (weights is None):
      #     warnings.warn('Provided copy=False and weights=None: a new Parafac2Tensor'
      #                   'with new weights and factors normalised inplace will be returned.')
      #     weights = T.ones(rank, **T.context(factors[0]))
  
      # The if test below was added to enable inplace edits
      # however, TensorFlow does not support inplace edits
      # so this is always set to True
      if True:
          factors = [T.copy(f) for f in factors]
          projections = [T.copy(p) for p in projections]
          if weights is not None:
              factors[0] = factors[0] * weights
          weights = T.ones(rank, **T.context(factors[0]))
  
      for i, factor in enumerate(factors):
          scales = T.norm(factor, axis=0)
          weights = weights * scales
          scales_non_zero = T.where(
              scales == 0,
              T.ones(T.shape(scales), **T.context(factors[0])),
              scales,
          )
          factors[i] = factor / scales_non_zero
  
      return Parafac2Tensor((weights, factors, projections))
  
imports: from .None import backend
  from .base import unfold, tensor_to_vec
  from ._factorized_tensor import FactorizedTensor
label_desc: Use image node_id 2 for calling a global function with example usage: parafac2_normalise(parafac2_tensor) and returns: Parafac2Tensor