code: def _samples_dicts_to_array(samples_dicts, labels):
      
      itersamples = iter(samples_dicts)
  
      first_sample = next(itersamples)
  
      if labels is None:
          labels = list(first_sample)
  
      num_variables = len(labels)
  
      def _iter_samples():
          yield np.fromiter((first_sample[v] for v in labels),
                            count=num_variables, dtype=np.int8)
  
          try:
              for sample in itersamples:
                  yield np.fromiter((sample[v] for v in labels),
                                    count=num_variables, dtype=np.int8)
          except KeyError:
              msg = ("Each dict in 'samples' must have the same keys.")
              raise ValueError(msg)
  
      return np.stack(list(_iter_samples())), labels
docs: Convert an iterable of samples where each sample is a dict to a numpy 2d array. Also
      determines the labels is they are None.