Week 3, class 1 .. question on a video slide

I have a question about something:

The vectorized version makes sense to me, however, I’m confused on the for loop and I still don’t see it:

I don’t understand how this could work because:

  1. The square brackets (a ^ [1], a ^ [2]) are the LAYERS
  2. m is the number of input samples – at least that’s what I think?
  3. The dimensions of “a” (a ^ [1] ^ (i)) in layer 2 aren’t related to the number of input samples, so how could you loop over the same number of input samples, a(i), in layer 2? (3rd line in the for loop)
  4. the dimensions of “a” in layer 2 should be related to the number of units in layer 1?

For the vectorized version, the number of examples doesn’t matter. The architecture controls the number of features (input) and units (for the hidden and output layers). The same algorithm applies regardless of the number of examples (m).

Using for-loops just makes the implementation more confusing. I don’t use for-loops myself.

What the for-loops do is force you to manually accumulate the results for each example or feature. Maybe this is instructive for students who aren’t comfortable with matrix algebra.

There are perfectly good (and efficient) functions provided for exactly this task (computing the sum of the products) in numpy.

Hello @Max_Solender,

This is a table of shapes. Please read this, Tom’s answers, all slides that discussed shapes, and then see if you can find the answers to your questions.

Cheers,
Raymond