# Hint - Incorrect on For loop Implementation:Excercise 1

J += np.square(r * (np.dot(w,x) + b_j - y ) )

In the Hint , the calcuation of the cost function is also including r(i,j) in the Square function., As per the formula, it does not seem right. I am not a Python export, but the hint (as in the line 1 seems incorrect)

the correct code should be as below

        J += r * np.square((np.dot(w,x) + b_j - y ))


Welcome to the community !

Actually, it does not matter…

r = R[i,j] = 1 or 0

And, we only calculate this if r=1.

Hope this clarifies.

Mathematically it does not. I did get distracted and received unrelated errors, until you bought the point out.

I did get distracted and received unrelated errors

Interesting… Did you actually implement the first one ?

Even mathematically,… no difference, of course.

$$r(i,j)*(w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)})^2= \begin{cases} 0 & \text{if r(i,j)=0} \\ (w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)})^2 & \text{if r(i,j)=1} \end{cases}$$
$$(r(i,j)*(w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)}))^2= \begin{cases} 0 & \text{if r(i,j)=0} \\ (w^{(j)}x^{(i)} + b^{(j)} - y^{(i,j)})^2 & \text{if r(i,j)=1} \end{cases}$$

What happened in your environment ?