code: def samples_to_batches(samples: Iterable, batch_size: int):
          
          it = iter(samples)
          while True:
              with suppress(StopIteration):
                  batch_in, batch_out = [], []
                  for i in range(batch_size):
                      sample_in, sample_out = next(it)
                      batch_in.append(sample_in)
                      batch_out.append(sample_out)
              if not batch_in:
                  raise StopIteration
              yield np.array(batch_in), np.array(batch_out)
docs: Chunk a series of network inputs and outputs into larger batches