Week 2 Exercise 1

I try to check my answer after exercise 1 and I got this error


TypeError Traceback (most recent call last)
in
5 cost = compute_cost(x_train, y_train, initial_w, initial_b)
6 print(type(cost))
----> 7 print(f’Cost at initial w: {cost:.3f}')
8
9 # Public tests

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

Hello @DrReda,

It seems like your compute_cost function is not returning a single cost value, which it should.

Could you DM (Click on My Name → Click On message → attach your notebook) me your notebook and I can take a look.

Thanks there was a bug indeed
solved now :slight_smile:

Hi moderator,

I have exactly the same problem.

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

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

Resulting in this error when grading my assignment:
Cell #UNQ_C2. Can’t compile the student’s code. Error: ValueError(‘The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()’)

Sytse

Hello @sytse06, looks like the test expects computer_cost to return a scalar value, but your implementation had returned an numpy array.

Raymond