Vectorized implementation of cost function

hi, I came up with below vectorized implementation to calculate the total cost.

def compute_cost(x,y,w,b):
# code removed

I am wondering why this vectorized implementation was not used during course? is there any issue with this implementation?

Please don’t post your code on the discussion forum. Thanks.

There is more than one “vectorized” method possible. In yours, you’re using an element-wise product followed by a summation. You can do those both in one operation with

Hey @Sujeet_Omar,
Welcome to the community.

For this question, I would like to highlight the philosophy of Prof. Andrew on the release of this specialization, which you can found in this LinkedIn post. This clearly explains why some topics have been included in the course and some topics have been excluded.

Additionally, you will find that vectorization has been used in a great depth in Course 2 of this specialization. It has not been used in the ungraded labs of Course 1, just to make sure that each and every learner can completely grasp the basics. However, I would strongly urge you to try the vectorized implementations in the graded labs for your practice if that is something you are interested in. I hope this helps.