code: def arrays2dict(iter, feature_cols, label_cols, shard_size=None):
      def init_result_lists():
          feature_lists = [[] for col in feature_cols]
          if label_cols is not None:
              label_lists = [[] for col in label_cols]
          else:
              label_lists = None
          return feature_lists, label_lists
  
      def add_row(data, results):
          if not isinstance(data, list):
              arrays = [data]
          else:
              arrays = data
  
          for i, arr in enumerate(arrays):
              results[i].append(arr)
  
      def merge_rows(results):
          result_arrs = [np.stack(l) for l in results]
          if len(result_arrs) == 1:
              result_arrs = result_arrs[0]
          else:
              result_arrs = tuple(result_arrs)
          return result_arrs
  
      def generate_output(feature_lists, label_lists):
          feature_arrs = merge_rows(feature_lists)
          if label_cols is not None:
              label_arrs = merge_rows(label_lists)
              return {"x": feature_arrs, "y": label_arrs}
          else:
              return {"x": feature_arrs}
  
      feature_lists, label_lists = init_result_lists()
      counter = 0
  
      for row in iter:
          counter += 1
          add_row(row[0], feature_lists)
          if label_cols is not None:
              add_row(row[1], label_lists)
  
          if shard_size and counter % shard_size == 0:
              yield generate_output(feature_lists, label_lists)
              feature_lists, label_lists = init_result_lists()
  
      if feature_lists[0]:
          yield generate_output(feature_lists, label_lists)
  
file_path: analytics-zoo/pyzoo/zoo/orca/learn/utils.py
imports: from zoo.common.utils import get_file_list
  from zoo.orca.data import SparkXShards
  from zoo.orca.data.utils import get_size
  from zoo.util.utils import convert_row_to_numpy
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: arrays2dict(iter, feature_cols, label_cols, shard_size) and returns: feature_lists,  label_lists, result_arrs, dict, dict