C1_W3_Exercise 4 - Prediction

Hi,
My function for Predict (week 3, exercise 4) produces a result that does not pass the test. Result:

*Output of predict: shape (4,), value [0. 0. 0. 1.] *

AssertionError: Wrong output: Expected : [1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0] got: [0. 0. 0. 0. 0. 0. 0. 1.]

if I change the indentation of my P ifelse statement to be in line with the nested loop above I get:

Output of predict: shape (4,), value [0. 1. 1. 1.]

AssertionError: Wrong output: Expected : [1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0] got: [1. 1. 1. 1. 1. 1. 1. 1.]

I’ve tried:

-rewatching the week three course videos but cannot find one on prediction so I’m a bit lost troubleshooting.
-experimented with various indentations of my ifelse code, the results change but still dont pass.
-Used all of the hints, and tried replacing my ifelse statement with the p[i] code provided in the hint, but this also doesn’t pass the test.

I know we’re not to display solution code here (although mine is wrong so perhaps there’s not harm?) but if someone could offer to help perhaps there’s a way i can share my code with you?

Many thanks for any support in advance,
James

Python is extremely picky about indentation - that’s how it defines blocks of code.

Review how you have your code indented. There should not be any guesswork.

  1. Please don’t post your code on the forum. That’s not allowed by the course honor code.
    If a mentor needs to see your code, we’ll ask you to send it via a private message.

  2. You have an indentation problem. Python defines code blocks using indentation. Since the function definition starts in column 1, everything (that isn’t a comment) below that must be indented.

So the indentation problem starts with the first line of code below the doctext block:
# number of training examples

Thanks Tom, I’ve deleted it, but getting to a point of desperation having been stuck here for a few weeks and have tried so many indentation combinations at this point i was convinced it must be the code. I’ll try again.

If you can’t fix it by just highlighting all your code and pressing “<tab>”, then download your notebook ipynb file and send it to me via a PM.

To get a PM, click on my name and use the “Message” button.