# Course 1 Week 3 Exercise 6

I am getting a type error for the np.sum when i am running the exercise 6 code. Please help.

Thanks,
Kiran

TypeError Traceback (most recent call last)
in
1 parameters, cache, t_X, t_Y = backward_propagation_test_case()
2
----> 3 grads = backward_propagation(parameters, cache, t_X, t_Y)
4 print ("dW1 = "+ str(grads[“dW1”]))
5 print ("db1 = "+ str(grads[“db1”]))

in backward_propagation(parameters, cache, X, Y)
50 dW2=np.dot(dZ2,A1.T)*(1/m)
51
—> 52 db2=(1/m)*np.sum(dZ2, axis=1, keepdims=“TRUE”)
53
54 dZ1=np.multiply(np.dot(W2.T,dZ2),(1 - np.power(A1, 2)))

<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: an integer is required (got type str)

The keepdims parameter of np.sum takes a Boolean value. You have given the string “TRUE”. The Boolean value would be True or 1. Or False or 0 if you want the other behavior. Also note that python is a case sensitive language. But the larger point is that “True” is not the same thing as True.

1 Like