Programming Assignment: Week 3 practice lab: unsupported format string passed to numpy.ndarray.__format_logistic regression:

Exercise 2:
TypeError Traceback (most recent call last)
5 initial_b = 0.
6 cost = compute_cost(X_train, y_train, initial_w, initial_b)
----> 7 print(‘Cost at initial w and b (zeros): {:.3f}’.format(cost))

TypeError: unsupported format string passed to numpy.ndarray.format

Hi @Sudipto_Das_Sukanto


This line tried to substitute {:.3f} with cost and format it to a number with 3 decimal places. However, it failed because, as suggested by the error message, cost was not a number, but an array:


Note that cost was returned from compute_cost which is an exercise of this assignment:


So, go back to the computer_cost exercise, and figure out why it did not return a number. Cost should be a number.

Good luck!

1 Like