tensorflow mnist tutorial
In a nutshell
If you have a look at what mnist.train is you'll find there are two numpy arrays in it:
mnist.train.images (shape (55000, 784))and mnist.train.labels (shape (55000, 10)).Then all you have to do is iterate on these.
Example
This example is voluntarily a bit complicated so that it is robust to whatever sizes you chose but keeps the idea of fixing a number of batches as primary information on how much you want to train on the dataset :
X_train = mnist.train.images
Y_train = mnist.train.labels
number_of_examples = X_train.shape[0]
batch_size = 1000
number_of_batches = 200
epoch = 0

for i in range(number_of_batches):
    

    j = (i - epoch) * batch_size % number_of_examples
    k = (i - epoch + 1) * batch_size % number_of_examples

    if (k &lt; j):
        k = number_of_examples
        batch_x = X_train[j:number_of_examples, :]
        batch_y = Y_train[j:number_of_examples, :]

        print('Shuffling data to retrain on dataset')
        data = numpy.concatenate((X_train, Y_train), axis=1)
        np.random.shuffle(data)

        # redefine X_train and Y_train from shuffled dataset
        X_train = data[:, :784]
        Y_train = data[:, 784:794]

        epoch = i + 1
    else:
        batch_x = X_train[j:k, :]
        batch_y = Y_train[j:k, :]

    # [...]
    train_step.run(feed_dict={x: batch_x, y_: batch_y, keep_prob: 0.5})

j is the row of the dataset which will be the batch's first row
k is the last one, so j-k=batch_size examples per batch, as expected.
Except if you've reached the end of the dataset (k&lt;j)
in which case you just go to its end and then shuffle the
dataset so that batches won't be the same.
You count i - epoch and not just i so that you're sure you'll always
start at the 1st row of the dataset even when you've already gone
completely through it.
For instance if number_of_examples = 55555, batch_size = 1000 and
number_of_batches = 200:  i = 56 is the first time you go again
through the (shuffled) dataset but 56 * 1000 % 55555 = 445 so you'd
start at row 445 and not 0.
Also you HAVE to concatenate, otherwise the pairs (example, label) will be lost.

i, j ,k % Whaaat?
Run the toy code below to see how the iteration index behaves:
number_of_examples = 55555
batch_size = 1000
number_of_batches = 200
epoch = 0

for i in range(number_of_batches):

    j = (i - epoch) * batch_size % number_of_examples
    k = (i - epoch + 1) * batch_size % number_of_examples

    if (k &lt; j):
        print('Overlap : ', j, number_of_examples)
        epoch = i + 1
    else:
        print(i, '   ', j, k)