Week 2 Exercise 2 (Understanding the logic case scaranos and output)

Hi, I have trouble understanding the logic when running the code, below 
One Case with a complete mini batch size only i.e each of 64 examples.   
mini_batch_X = shuffled_X[:,(k*num_complete_minibatches):((k+1)*(num_complete_minibatches))]
    mini_batch_Y = shuffled_Y[:,(k*num_complete_minibatches):((k+1)*(num_complete_minibatches))] 


And other for handling the end case (last mini-batch < mini_batch_size i.e less than 64)
 mini_batch_X = shuffled_X[:,(k)*(m-mini_batch_size*num_complete_minibatches):(k+1)*(m-mini_batch_size*num_complete_minibatches)]
        mini_batch_Y = shuffled_Y[:,(k)*(m-mini_batch_size*num_complete_minibatches):(k+1)*(m-mini_batch_size*num_complete_minibatches)]

After that, here is my output. 
![opt1|690x397](upload://qwGzhEwJ5zjNZxRSeOumI80tGEw.png)
![opt2|690x404](upload://r0gTyDtQI6N2CmM6zbV4i6fRRqG.png)

I want to know how to proceed this properly. (i.e. refer to some examples and relevant slides, etc.). Thank you.


Please think through what needs to happen in terms of the indexing to extract the various minibatches. Why is k * num_complete_minibatches relevant in that context? It is the size of the minibatches that is important there, not the number of minibatches, right? So the first one starts at index 0 and includes mini_batch_size elements. So how would you express that as a start:end index range in python?

1 Like


I got all the tests passed. Now, I figure out why my shape for the final batch is not matched.

Interesting. Note that the size of the last partial batch was correct in the first version that you posted at the beginning of this thread (size = 20). So you fixed the full minibatch case, but now the partial case is broken in the same way that the full version was broken the first time around (size = 2).

That seems like a useful clue as to the nature of the error. :nerd_face: