in nn_model(X, Y, n_h, num_iterations, print_cost)
27 # YOUR CODE STARTS HERE
28
—> 29 parameters = initialize_parameters(n_x,n_h,n_y)
30
31 # YOUR CODE ENDS HERE

in initialize_parameters(n_x, n_h, n_y)
22 # YOUR CODE STARTS HERE
23
—> 24 W1 = np.random.randn(n_h,n_x) * 0.01
25 b1 = np.zeros([n_h,1])
26 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

It looks like there is a problem with the way n_x, n_h is extracted. Please check. The code for extracting these values should already be given to you.

Thanks for your inputs.
I tried to understood but in the code i found that n_ x and n_h are the input parameters of the function initialize_parameters.i used these values for calculating the value of W1.
If I missed something then please correct me.
Thanks again.

If A and B are two 2D numpy.arrays, then numpy.concatenate(A,B) yields the error.

The fix was to simply to add the missing brackets: numpy.concatenate( ( A,B ) ), which are required because the arrays to be concatenated constitute to a single argument.

so check you parameter intialization has been recalled as per above mentioned, I noticed you have used an incorrect bracket.

Thank you for your help.
I am little confuse in the usage of numpy.concatenate in my code snippet.
I am not getting where exactly I need to add the missing brackets.

could you please give me more hints so i can try it again ?
Thanks in advance.

I think you are missing the point that Kic is making. The question is how the values of n_x, n_h and n_y are determined in nn_model before you pass them to initialize_parameters. Either n_h or n_x must not be a scalar integer value. Print them out before the call to the initialize routine. Kic’s other point is that all those values are just given to you, so if they are incorrect, you must have modified part of the code that you did not need to modify.

I confess that I am also confused by this. I did not use np.concatenate anywhere in my code. It should not be required. So Deepti must be making some higher level point here.

Maybe one relevant point to make is to note that the APIs to np.zeros and np.random.randn are fundamentally different. np.zeros takes a single “tuple” as the argument giving the dimensions you want. For np.random.randn, you just give a list of individual parameters as the dimensions. But we’re not really talking about how those APIs work here: your initialize routine already passed the local test cases, I assume, right? The question is what the values are that you are passing from nn_model when you call the lower level routine.

But that’s not the line that “threw”, right? It was the randn line that threw. And if the code passed the test case, I’m guessing that implementation works.

Update: I changed my code to use square brackets instead of parens to create the arguments for np.zeros and it works fine for me and passes the test cases both for initialize_parameters and nn_model.

initialize_parameters method having following parameters
n_x – size of the input layer
n_h – size of the hidden layer
n_y – size of the output layer

When i called this method from nn_model method I passed the values n_x and n_y return by
n_x = layer_sizes(X, Y)[0]
n_y = layer_sizes(X, Y)[2]

This was the issue,
For resolving this issue, as suggested by @paulinpaloalto I use print statement before the function call.
It returns array for n_x and n_y respectively.
Then I pass respective index of n_x and n_y to the initialize_parameters method.
This resolves the issue.