code: def array_from_nested_dictionary(
      nested_dict, array_fn, dtype="float32", square_result=False
  ):
      """
      Parameters
      ----------
      nested_dict : dict
          Dictionary which contains dictionaries
  
      array_fn : function
          Takes shape and dtype as arguments, returns empty array.
  
      dtype : dtype
          NumPy dtype of result array
  
      square_result : bool
          Combine keys from outer and inner dictionaries.
  
      Returns array and sorted lists of the outer and inner keys.
      """
      if square_result:
          outer_key_indices = (
              inner_key_indices
          ) = flattened_nested_key_indices(nested_dict)
      else:
          outer_key_indices, inner_key_indices = nested_key_indices(
              nested_dict
          )
  
      n_rows = len(outer_key_indices)
      n_cols = len(inner_key_indices)
      shape = (n_rows, n_cols)
      result = array_fn(shape, dtype)
      for outer_key, sub_dictionary in nested_dict.items():
          i = outer_key_indices[outer_key]
          for inner_key, value in sub_dictionary.items():
              j = inner_key_indices[inner_key]
              result[i, j] = value
      outer_key_list = index_dict_to_sorted_list(outer_key_indices)
      inner_key_list = index_dict_to_sorted_list(inner_key_indices)
      return result, outer_key_list, inner_key_list
  
imports: from collections import defaultdict
  import numpy
  from scipy.sparse import dok_matrix
label_desc: Use image node_id 6 for calling a global function with example usage: array_from_nested_dictionary(nested_dict, array_fn, dtype, square_result) and returns: result,  outer_key_list,  inner_key_list