title: tensorflow next_batch vs custom next_batch?
body: <p>I'm trying to write a function that can get batches of data, similar to tensorflow's next_batch.</p>
  
  <p>next_batch can be seen here:
  <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/mnist.py" rel="nofollow noreferrer">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/mnist.py</a></p>
  
  <p>This is the code that I wrote.</p>
  
  <pre><code>class Sampler:
  
  def __init__(self, data):        
      self.x, self.y = data
      self.N, = self.y.shape
      self.start = 0
      self.shuffle = np.arange(self.N)
      np.random.shuffle(self.shuffle)
      self.x = self.x[self.shuffle]
      self.y = self.y[self.shuffle]
  
  def sample(self, s):
      start = self.start
      end = np.minimum(start+s, self.N)
      data = (self.x[start:end], self.y[start:end])
      self.start += s   
      if self.start &gt;= self.N - 1:
          self.start = 0
          np.random.shuffle(self.shuffle)
          self.x = self.x[self.shuffle]
          self.y = self.y[self.shuffle]
      return data
  </code></pre>
  
  <p>I feel that this is a natural approach, but while I can get 99%+ accuracy with classification using next_batch, I can only get around 50% using my "sample" function.</p>
  
  <p>Could anyone help me understand what's going on?</p>