Need help understanding function in computation of gradient

{moderator edit: code removed}

Why is the 2nd line not applicable, correct me if i wrong but if both are arrays (dj_dw and w) cant i just add them together? (ps: sorry if its a low level qn in advance!!!)

Hi @zheng_xiang1
Welcome to the community!

If you calculate the gradient you have to go through every feature of each training example. In the loop n is the number of features. It’s an inner loop.

1 Like

In fact, you do not really even need the for-loop over the features, because you can implement that using a vector math operation.

Also, please don’t post your code for the programming assignments on the forum. Sharing your code isn’t allowed by the community standards. I’ve edited your OP.

1 Like

first of all sorry for the initial post. As for clarifications on my code, on the 2nd line i was attempting to use vector math operations but it didnt work. could u prompt me on where did the operation resulted in the error?

tks for the explanation!!! :3