Course 2: week 2

I am unable to understand this formula when the mini-batch size is not multiple of 64? Elaborate on this formula on how it finds the last mini batch.

Hi, @khirman.

\lfloor \frac{m}{mini\_batch\_size} \rfloor is just the integer division of m and mini\_batch\_size (i.e., the number of mini-batches of size mini\_batch\_size that go into m). So the first loop creates \lfloor \frac{m}{mini\_batch\_size} \rfloor mini-batches of size mini\_batch\_size. That’s a total of mini\_batch\_size \times \lfloor \frac{m}{mini\_batch\_size} \rfloor examples. If you subtract this number from the number of examples, m, you get the number of examples remaining for the last mini-batch.

Good luck with the assignment :slight_smile:

1 Like

@nramon
I still don’t understand u should compute it with an example :sweat:

According to the assignment, it should be something like :
148 - 64*(148/20)

That 20, which is the size of the last mini-batch, is what you’re trying to figure out. You don’t know it yet.

You have m = 148 and mini_batch_size = 64.

So you substitute in the formula and get: m - mini_batch_size * math.floor(m / mini_batch_size) = 148 - 64 * math.floor(148 / 64) = 148 - 64 * 2 = 20.

Let me know if it’s clear now :slight_smile:

2 Likes