Factorization formula issue ?!

Hi Gays I hope that you are doing well.

When i was trying to practice in the 2nd week lab " Linear regression," exactly in the first exercise, which was the implementation of the cost function using Python, I used the factorization formula using numpy arrays, as you see in the pictures below, but it didn’t give the right expected output compared with the other method using the for loop. So where is the problem. There is a problem in my factorization formula for the predict function!

Thanks
{moderator edit: code removed}


Try running the following code and watch what happens:

m = 5.
x = 1. / 2. * m
y = 1. / (2. * m)

If you’re expecting x and y to have the same value, you’re in for a surprise. Note that you did it correctly in the second case, but not in the first case.

1 Like

Oh, I feel really silly about this! I didn’t notice the brackets. I thought there was a mistake in how the equation was written. Thank you for bringing it to my attention. It works now, and I think it is the optimum method. thanks again

In the future, please avoid posting your code on the forum. That’s not allowed by the Code of Conduct.