def gen_batches(n, batch_size):
 start = 0
 for _ in range(int((n // batch_size))):
  end = (start + batch_size)
  (yield slice(start, end))
  start = end
 if (start < n):
  (yield slice(start, n))

def gen_batches ( n , batch_size ) : start = 0 for _ in range ( int ( ( n // batch_size ) ) ) : end = ( start + batch_size ) ( yield slice ( start , end ) ) start = end if ( start < n ) : ( yield slice ( start , n ) )
generator to create slices containing batch_size elements .