code: def build_xn_vn_array(xn):
      """
      This function constructs array-ified (not nested) versions
      of the posterior xn (beliefs) or vn (prediction error) arrays, that are separated
      by iteration, hidden state factor, timepoint, and policy
      """
  
      num_policies = len(xn)
      num_itr = len(xn[0])
      num_factors = len(xn[0][0])
  
      if num_factors > 1:
          xn_array = obj_array(num_factors)
          for factor in range(num_factors):
              num_states, infer_len = xn[0][0][factor].shape
              xn_array[factor] = np.zeros(
                  (num_itr, num_states, infer_len, num_policies)
              )
          for policy_i in range(num_policies):
              for itr in range(num_itr):
                  for factor in range(num_factors):
                      xn_array[factor][itr, :, :, policy_i] = xn[
                          policy_i
                      ][itr][factor]
      else:
          num_states, infer_len = xn[0][0][0].shape
          xn_array = np.zeros(
              (num_itr, num_states, infer_len, num_policies)
          )
          for policy_i in range(num_policies):
              for itr in range(num_itr):
                  xn_array[itr, :, :, policy_i] = xn[policy_i][itr][0]
  
      return xn_array
  
imports: import numpy
  import pandas
  import seaborn
  import matplotlib.pyplot
  import warnings
  import itertools
label_desc: Use image node_id 35 for calling a global function with example usage: build_xn_vn_array(xn) and returns: xn_array