MLS Course 1 week 2 optional lab 02


I’m unable to understand what is the use of this yellow box content.
why we are storing values in J_history?
how is this line working=> print(f"Iteration {i:4d}: Cost {J_history[-1]:8.2f} ?

Hi @Samy2705

So that we can plot the cost graphs a few cells below. For more on what we can do with it, Course 2 Week 3 lectures will cover it.

This is called “Formatted String”. Here is one explanation but you might search for more examples with that name.

Cheers,
Raymond

J_histiory and j_hist are same?

{J_history[-1]:8.2f} => what is the use of -1 in it?
correct me if I’m wrong :
j_history[-1] = last value of list j_history
{j_history[-1] : 8.2f } it means from last value of j_history to 8th place value with 2 point precision example : 40.25

They are two variables, but if you assign the content of J_history to J_hist, then they represent the same thing.

f'{40.25:8.2f}' will give us ' 40.25'. Note the spaces.
I got the above result by running it in a jupyter notebook, and I encourage you to test more!

Raymond