Hello, @tamalmallick,
To help me answer your question for you and for any one who comes to this in the future, let’s use this screenshot that shows a few more lines:
The code can compute cost in two ways where “version 1” is the form taught in the lecture but “version 2” is not. “Version 2” is supposed to be derived from version 1 and in this post you may see how we can derive a different form from version 1.
However, the thing here is that even we can derive a version 2, the one shown in the code is not correct as it is different from my result in the linked post in two ways.
Btw, I did a quick check and found that the function that include this piece of code is not really used by any optional lab. Let me know if I am wrong because it was really just a quick check.
Cheers,
Raymond