Week2, print_cost = False/True?

Hello,
I’m a little confused on how setting print_cost = False/True works. For example in Exercise 6 (Optimize function), in the function definition we have def optimize(…,print_cost = False):
but then inside the function we have
if i % 100 == 0:
costs.append(cost)

        # Print the cost every 100 training iterations
        if print_cost:
            print ("Cost after iteration %i: %f" %(i, cost))

My question is when is print_cost reset to True so that the print() function knows to print the cost for every 100 training iterations?

Thank you,
Nay

Hi @Nay, as print_cost is a parameter of the function if you want to see the print outs then you need to pass explicitely print_cost=True when calling the function.

The default behaviour is that there will be not any print out, you must “ask” for it when calling the function.

Kind regards

1 Like