Hi everyone!
I don’t understand what’s going on
{moderator edit - solution code removed}
maybe it somehow causes another error
Hi everyone!
I don’t understand what’s going on
{moderator edit - solution code removed}
maybe it somehow causes another error
Hello @novosadkatie
The unit test is failing because your implementation of n_x and n_y inside the function “layer_sizes” is not dependant on the X,Y arguments that are getting passed into the function.
Your logic for n_x and n_y are hardcoded with values that were evaluated outside of the function. So, when the unit test passes in a different value of X and Y (this happens behind the scenes), your function implementation will still return the n_x and n_y calculated with respect to the global X and Y defined outside of the function…and hence the mismatch with the answer that the unit test is expecting.
Thank You!
How can I fix this?
Instead of directly using shape_X and shape_Y inside the function, redo what you did earlier to find shape_X and shape_Y once again inside the function.
Exactly. The point is that shape_X
and shape_Y
are not defined anywhere in the local scope of that function, right? So how will that ever work? You need to use the actual parameters that were passed in.
BTW You filed this under the new M4ML specialization, but it looks to me like it’s about DLS C1 W3. You can move it by using the little “edit pencil” on the title. Or I can do that for you if you confirm that I’ve made the correct deduction here about where it really belongs.
Hello @paulinpaloalto
This is from the lab of the new M4ML specialization.
Oh, sorry. Thanks for the clarification. It looks like they did copy it from DLS C1 W3, though.
Hi, Can you elaborate please? I am also stuck in this assignment and I don’t quite understand what you’re trying to say. Thank You
I’m getting exactly the same error. I know it has something to do with the original shapes of the arrays, but I have no idea how to fix that within the unit test.
I’ve gotten this far: (apologies in advance if I am not supposed to post any code. This is not a solution, just a deduction).
I ran a test:
print(shape_X)
print(X.shape)
print(shape_Y)
print(Y.shape)
My result was:
(1, 30)
(5, 6)
(1, 30)
(3, 10)
So I know the size of the original arrays, I just don’t know how to call them or implement them within the 2 lines of code I am expected to write.
The arrays to be used are passed in as arguments, right? Just use those. So the question is, how many rows are in the X matrix that is passed as the first argument? We saw how to figure that out earlier in the notebook. Each numpy object has an “attribute” called “shape”. If I have a 2 dimensional numpy array called myArray
and I write this code:
theShape = myArray.shape
Then the newly defined python variable called theShape
, will be a “tuple” with two elements: the first element will be the number of rows in myArray
and the second element will be the number of columns in myArray
. So if I need the number of rows, that would be:
theRows = theShape[0]
Because indexing in python is “0-based”, right?
But I think the issue you are having is more fundamental. The variable shape_X
was defined earlier in the notebook and has nothing to do with the value of X that was passed by that test case. You can clearly see that from the print statement outputs, right? It is always a mistake to reference global variables from the scope of your functions. If you don’t understand what I mean by that statement, you really should consider taking a python course first. I think we’ve already discussed that on another thread, right?
I solved it, with your help. Thank you.
And yes, I have already started the introductory Python course recommended by another moderator in this forum.
But I don’t renew my subscription until the end of the month, so I’m going to fight it out until then, and continue to build the plane while flying it.
Definitely expecting to crash, but what I learn will be valuable.
Thanks again for taking the time to respond.
Great! If you want to get more info on the specific point that I was making there about global variables, try googling “python scoping model” and spend half an hour reading up on that. E.g. here’s one of the top few “hits” that I got from that search.
I might have spoken too soon, I passed all four tests, but when I submitted for grading, I got:
Failed test case: Object layer_sizes has incorrect type…
Expected:
<class ‘function’>,
but got:
<class ‘NoneType’>.
I think that means I did not properly return the function somehow.
Still working on it…And looking at your link now.
Did you modify the “def” statement for that function? In general it’s a mistake to modify anything outside the “YOUR CODE HERE” segments. It’s not illegal, but you had better be very sure you know what you are doing when you “go there”.
That error message is telling you that the definition of the variable “layer_sizes” is “None”. But it was originally defined to be a function, right? So how could that happen?
Try doing “Kernel → Restart and Clear Output”, then “Save” and then “Cell → Run All”. Now go back and check that the test cell for the layer_sizes
function worked or not.
We’re writing computer code here, not English prose, right? So every single character matters. You can’t just throw an extra space or a comma in someplace because you think it makes it look nicer. The difference between : and ; can ruin your whole afternoon. Careful attention to detail is required.
Also note that indentation is part of the syntax of python. You can’t just mess around with the indentation for aesthetic reasons.
No, I did not modify the “def” statement.
I followed your instructions but received the same result.
How do I restart the assignment from scratch?
Please “copy/paste” the full exception trace that you are getting that ends in the error message you show.
If you do want to start from a clean copy of any of the notebooks, there is a way to do that, as described on this thread.
Failed test case: Object layer_sizes has incorrect type…
Expected:
<class ‘function’>,
but got:
<class ‘NoneType’>.
Is this what you need?
What I was hoping for was more “context”. What were you doing when you got that message? That’s only the terminus of the exception trace. What is above that? Usually it leads all the way back to the “root” which is the function you executed at the “top level”.
But here’s a simpler question: after you get that message (however you got it), go back to the test cell that checks the layer_sizes function. Run that test cell again and let me know what happens.