Course 1 Week 3 : Programming Assignment Type Error

All the above tests passed correctly , but stuck on this error on Exercise 8 nn_model.
It shows below error message.
Type Error : only integer scalar arrays can be converted to a scalar index.

TypeError Traceback (most recent call last)
in
1 t_X, t_Y = nn_model_test_case()
----> 2 parameters = nn_model(t_X, t_Y, 4, num_iterations=10000, print_cost=True)
3
4 print("W1 = " + str(parameters[“W1”]))
5 print("b1 = " + str(parameters[“b1”]))

in nn_model(X, Y, n_h, num_iterations, print_cost)
22 # parameters = …
23 # YOUR CODE STARTS HERE
—> 24 parameters = initialize_parameters(X, n_h, Y)
25
26 # YOUR CODE ENDS HERE

in initialize_parameters(n_x, n_h, n_y)
24 # b2 = …
25 # YOUR CODE STARTS HERE
—> 26 W1 = np.random.randn(n_h, n_x) * 0.01
27 b1 = np.zeros((n_h, 1))
28 W2 = np.random.randn(n_y, n_h) * 0.01

mtrand.pyx in numpy.random.mtrand.RandomState.randn()

mtrand.pyx in numpy.random.mtrand.RandomState.standard_normal()

_common.pyx in numpy.random._common.cont()

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

How is it that it passed above tests and failed in this one ?

Check how the function initialize_parameters is defined:

def initialize_parameters(n_x, n_h, n_y):

And compare it with the way you are calling it: —> 24 parameters = initialize_parameters(X, n_h, Y)

1 Like