MLS Week 3 -Exercise 4 - To calculate predict funtion

I am trying to complete the predict function, but encountering with assertion error:

I used below loop in the function, to insert the predicted value into the vector:
if f_wb >= 0.5:
p[i] = 1
elif f_wb < 0.5:
p[i] = 0

Below is the error, I am getting, when I ran the test:

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

AssertionError Traceback (most recent call last)
in
9
10 # UNIT TESTS
—> 11 predict_test(predict)

~/work/public_tests.py in predict_test(target)
69 raise ValueError(“Did you apply the sigmoid before applying the threshold?”)
70 assert result.shape == (len(X),), f"Wrong length. Expected : {(len(X),)} got: {result.shape}"
—> 71 assert np.allclose(result, expected_1), f"Wrong output: Expected : {expected_1} got: {result}"
72
73 b = -1.7

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.]

Expected output

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

I tried a couple of ways to fix this, but no luck. Any help is greatly appreciated.

Hi!

Can you send me your code in a direct message and I’ll take a look.