I want to create a class that will be able to apply transformations, including shuffle, to a dataset. The prototype I came up with looks something like this:
import numpy as np
class Dataset:
  def __init__(self, src, tgt):
    self.src = src
    self.tgt = tgt
    self.gen = ((s, t) for (s, t) in zip(self.src, self.tgt))
    
  def __iter__(self):
    return self.gen
  
  def __next__(self):
    for pt in self.gen:
      return pt
      
  def shuffle(self):
    self.gen = (pt for pt in np.random.shuffle([pt for pt in zip(self.src, self.tgt)]))
The generator self.gen is successfully created, but I get an error when using .shuffle() method:
self.gen = (pt for pt in np.random.shuffle([pt for pt in zip(self.src, self.tgt)]))
TypeError: 'NoneType' object is not iterable
I understand that the generator is not created, but I do not understand why. Would appreciate some help and explanation why my attempt was futile.
 
    