Week 2 - Difficulty with random_mini_batches containing 'Wrong Values'

I’m having difficulty getting the random_mini_batches (Exercise 2) code to pass the first test block. I get the following error:

The shape of the return mini_batches is correct and when inspecting the values they also appear to be correct.

My start and end indexes for each mini_batch are as follows:
[0, 64), [64, 128), [128, 148)

The test block following this passes (random_mini_batches_test).

I’m not sure what mistake I’m making, does anyone have any hints?


I am not sure how you are implementing the code.
Here is the instruction in the notebook:

first_mini_batch_X = shuffled_X[:, 0 : mini_batch_size]
second_mini_batch_X = shuffled_X[:, mini_batch_size : 2 * mini_batch_size]

Let me translate this when using for loop range(0, num_complete_minibatches):

mini_batch_X = shuffled_X[all rows, number of loop multiplied by the size of minibatch: number of loop plus 1 and then multiply by the size of minibatch]

This appears to be exactly what I have implemented. Am I able to send you my solution?

So I’ve done a little more digging and I only get the problem when running the notebook locally on Python 3.10.13 with numpy 1.26.0.

When I run it online the assertion passes.

To run it locally, you have to use the same version of all the libraries as used by Coursera…