2

I have two generators:

generator1 = CustomGen(X1,X1, length=W, stride = 1,sampling_rate=1, batch_size=bt_size)
generator2 = CustomGen(X2,X2, length=W, stride = 1,sampling_rate=1, batch_size=bt_size)

that are created using the function adopted from Custom Data Generator for Keras LSTM with TimeSeriesGenerator:

class CustomGen(TimeseriesGenerator):
    def __getitem__(self, idx):
        x, y = super().__getitem__(idx)
        # do processing here
        return x, x

Each object has m number of batches. I would like to join these two objects into one having a total of 2m batches.

kosist
  • 2,868
  • 2
  • 17
  • 30

1 Answers1

2

itertools.chain could be your friend here:

generator = itertools.chain(generator1, generator2)

It will return all elements from generator1, followed with elements from generator2.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • Thank you for your reply. The output of chain is not of the same type of generator1 (or generator2) type. Is there an althenative way as such the object type is retained. – Ayomi Al-noor Oct 31 '19 at 10:33