[code removed - moderator]

How did you guys implement the cost function? See my attempt and help

[code removed - moderator]

How did you guys implement the cost function? See my attempt and help

The last term is incorrect. Please fix it keeping in mind that `A2`

is in probability scale.

Don’t forget to remove code from your post.

Thanks! I made the correction as follows:

[code removed - moderator]

it worked.

I have a type error. Please advise!

Term 1 logprobs: [[-0.69268589 -0. -0. ]] Term 2: [[0. 0.50014169 0.49976037]]

TypeError Traceback (most recent call last)

in

1 A2, t_Y = compute_cost_test_case()

----> 2 cost = compute_cost(A2, t_Y)

3 print("cost = " + str(compute_cost(A2, t_Y)))

4

5 compute_cost_test(compute_cost)

in compute_cost(A2, Y)

27 print(‘\n\n’)

28

—> 29 cost = (-1/m) * np.sum((logprobs),((1-Y)*np.log(1-A2)))

30

31 # debug

<**array_function** internals> in sum(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in sum(a, axis, dtype, out, keepdims, initial, where)

2227

2228 return _wrapreduction(a, np.add, ‘sum’, axis, dtype, out, keepdims=keepdims,

→ 2229 initial=initial, where=where)

2230

2231

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)

88 return reduction(axis=axis, out=out, **passkwargs)

89

—> 90 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

91

92

TypeError: only integer scalar arrays can be converted to a scalar index

@Brendon_Wolff-Piggot

Please read the markdown for the exercise. Your computation of `logprobs`

and eventually the `cost`

is incorrect.

If it helps, see the definition of `J`

just above the writeup for `Exercise 5 - compute_cost`

section.

I’m sure you’re right. I just didn’t come right looking at the code at the top of the exercise.

I ended up going back to the line I used in the backpropagation assignment and it worked immediately. Is there a place to look at model answers when the assignment is closed?

No, sorry, there are no “official solutions” that you can use as a reference. My guess is that this is because of concerns about cheating. Where would they put those in such a way that you can only see them *after* you’ve completed the exercise and how do they prevent them from being shared?

Onwards and upwards then…