Hi, when i use the following code, i get the following output
Size of input layer.
n_x = np.shape(X[0])
The size of the input layer is: n_x = (30,)
instead of the expected output
The size of the input layer is: n_x = 1
How do i grab the “1” instead of “30” in X ? Please help…stuck here
Thank you
Try n_x = np.shape(X) or n_x = np.shape(X)[0]
The reason you are getting the output n_x = (30,)
is because the X
variable is a 30-dimensional array. To get the first dimension of the array, you can use the X[0]
syntax. For example, the following code will print the first dimension of the X
array:
X = np.array([1, 2, 3, 4, 5])
X[0]
1
In your case, you want to get the first dimension of the first element of the X
array. To do this, you can use the following code:
n_x = np.shape(X[0])[0]
n_x
1
This code will print the value 1
, which is the first dimension of the first element of the X
array.
For this reason, the following line would return what you have asked for:
n_x = np.shape(X)[0]
I hope this helps! Let me know if you have any other questions.
1 Like
It works now, thank you for the prompt assistance!