Doubt in random_mini_batches (week 2 - exercise 2)


can someone tell me why this happening. I think the shape of the mini_batches is OK but I have this 2 test failled.


1 Like

also show me this error but I dont know what it´s talking about


Please add your implementation so we can figure out what might be wrong:)

This is my implementation.
{moderator edit - solution code removed}

This is the error msg.

k increases from 0 to number of complete mini batches, but you don’t extract mini batches using your incrementor k. For every mini batch, you extract the same slice. You get a hint before the exercise describing how the first two minibatches are calculated. Can you figure out how k fits into that equation?


Thank you so much, sir, for guiding me to solve it by myself instead of showing me the solution.
I learned from my mistake. :pray: :relaxed:


Maybe, It’s not important now, but
mini_batch_X = shuffled_X[:, 0:m - (inc*num_complete_minibatches )] isn’t a good idea too.
The correct version is mini_batch_X = shuffled_X[:, important_point:] and
important_point is an obvious point)))

1 Like

This passes only one test .

@rajat please let me know the exact solution . Trying since long.

@A_12_EESHAN_BHANAP You can add your implementation and the error message so we can figure out what might be wrong. :slightly_smiling_face:

Hello all,

I am running into the same error, “Wrong values. Check the indexes used to form the mini batches”. I have read each reply and after a few hours thinking it over, I am still confused. I coded my algorithm on my local computer in Spyder and gave it some test cases and they all worked as intended. So I am unsure how I am failing 1 of the 3 test cases in Jupyter.

I saw that 1 reply had their code removed due to honor code so I will not post it, rather describe the general formula I wrote:

in the first for loop k (0 through number of complete batches):
I have it taking every row in every sample to maintain dimensionality. As for the indexing across samples, I simply go from k times the minibatch size to (k+1) times the minibatch size as that is what is happening in the provided example code.

lastly, if there are any leftover samples remaining, I start at the last complete batch possible to the very end. (number of complete batches*number of batches to end)

I am very confused on where to go from here. At first, I did not use the number of complete batches to get the remaining samples, and that produced a bug where if the number of samples provided was less than the sample batch it would return a list of 0. However, using the number of complete batches variable fixes this.

Is there another circumstance I am not accounting for in my current implementation that could be in the tester and therefore failing me on one of the tests?

Thank you in advance for the help and your time!

The test cases can be examined by clicking “File → Open” and then opening the file Maybe seeing what is different about the test cases you fail might be a clue.

Actually there are two test cells for that function. In the first one, all the tests are written out right there in the cell. Then there is a second cell in which it invokes a function from

I think that the message you show comes from the first cell. That is the very last of the test cases. Examining that code carefully to see what it is actually checking would be a productive line of inquiry.

I checked the test case in public_tests. py and they have a minibatch size of 2 and an input m value of 3, so it’s a pretty small test case.

The first cell, which provides this error:

The second cell, shows that I pass 2 of the 3 tests.

But in those test routines they test every variable in three ways typically:

  1. The type of the variable
  2. The shape of the variable
  3. The actual values of the variable

So passing 2 out of 3 tests should not be much comfort. In the first cell, it also looks like everything is the correct shape, but the values are wrong. So how could that happen?

Ok, looking at that test, parse what it is checking:

minibatches is an array of 2-tuples (batchX, batchY), right?

So the indexes [0][0] give you the X array of the very first minibatch.

Then it indexes that as X[0][0:3], so it is selecting the first 3 elements of the first row of that X matrix, right? And that’s already wrong. The very first minibatch has the wrong values in the first row of the X array. So how could that happen?

I really appreciate the replies. Unfortunately after printing out what X is, what my mini batch algorithm gives, and what the expected is. I am confused why the tester is expecting that result and not mine.

I am simply activating the cell under the random_mini_batches function to get what X is and calling the random_mini_batches function with my algorithm. [0:3] should be the first 3 indexes within that mini batch, correct? why does it expect: [294912, 860016, 454656]?

Thank you again!