Wondering if the third question has error as the “for j in range(n):” appeared twice inside the first loop? I know we are supposed to fill in places where there is “None”, but the structure of the codes given is a bit strange compared with the example given in the course.
It is not an error, because we can have one to compute the prediction and one for the gradients. The latter can only be computed after the former is done, so these two steps can’t be combined into one.
Cheers.
But the example in this lab 06 only contain 2 loops whereas the exercise 3 contains 3 loops. They are both intended to compute gradient for logistic regression. A bit confused of the logic.
Loop can be replaced by vectorization. We can implement that with 2, 1, or 0 loop.
Andrew has explained that in Course 1 Week 2 lectures for “vectorization”. I encourage you to check those out to refresh your memory, because even though you can use the loop approach for the rest of this course, which is the basic approach for this beginner course, vectorization is the common approach in the real world.
Raymond
Andrew tends to use for-loops when teaching these introductory courses, because he feels is it easier to understand for students who do not have a strong background in linear algebra (which would typically use a matrix product instead of iterating over the rows and columns).