code: def expand_triangular(X, k):
      
  
      X = X.tolist()
      # Unflatten matrix
      Y = np.asarray(
          [[0] * i + X[i * k - (i * (i - 1)) / 2: i * k + (k - i)] for i in range(k)])
      # Loop over rows
      for i in range(k):
          # Loop over columns
          for j in range(k):
              Y[j, i] = Y[i, j]
      return Y
docs: Expand flattened triangular matrix.