Week3 assignment, Exercise 2, why error


I did the below code for Exercise 2, and I get only half points.

Does anyont know what is the error here?

You have posted this under DLS Course 1, but that is not what this assignment looks like in DLS Course 1 Week 3. Here’s the test cell for layer_sizes that I see in the Planar Data Assignment:

t_X, t_Y = layer_sizes_test_case()
(n_x, n_h, n_y) = layer_sizes(t_X, t_Y)
print("The size of the input layer is: n_x = " + str(n_x))
print("The size of the hidden layer is: n_h = " + str(n_h))
print("The size of the output layer is: n_y = " + str(n_y))


That’s very different than what you show. Are you sure this is not MLS or perhaps Math for ML?

But this function is very similar to the one in DLS C1 W3 and we can note that your code is quite a bit more complicated than it needs to be. There is no need to use np.size. Just the shape of X and Y are all you need to get the layer size values.

This post belongs to the linear algebra course.

As Paul mentioned, you simply need to use the shape function. For example, If I want to grab the columns of matrix A, it would be A.shape[1]. Now think about it. Do you need to grab the rows or columns?


Thank you so much - the tips helped solve my error :slight_smile: Yes sorry I’m taking Linear Algebra for Machine Learning course… First time using this community