C1W3 - Programming assignment - Prediction

I’m getting this error since yesterday even though I’ve followed the hints completely. Could you please help me out?

ValueError: setting an array element with a sequence.

Error -
36 # Apply the threshold
—> 37 p[i] = (f_wb>= 0.5)
38
39 ### END CODE HERE ###

m, n = X.shape
p = np.zeros(m)

### START CODE HERE ### 
# Loop over each example
for i in range(m):   
    z_wb = 0
    # Loop over each feature
    for j in range(n): 
        # Add the corresponding term to z_wb
        z_wb += np.dot(X[i,j],w) 
    
    # Add bias term
    z_wb += b
    
    # Calculate the prediction for this example
    f_wb = sigmoid(z_wb)

    # Apply the threshold
    p[i] = (f_wb>= 0.5)
    
### END CODE HERE ### 
return p

Hi @Aishwarya_Koushik

Check again to see if np.dot() is the operation you want to use.

Hope this helps!

I tried it and it worked. Thank you so much!
I’ve always used .dot() and it has worked too. Not sure what happened all of a sudden. Why could this be?

1 Like

A post was split to a new topic: C1 W3 predict - UnboundLocalError: local variable ‘cost’ referenced before assignment

what changes to made in p[i] = (f_wb>= 0.5) this code statement?

Hi,

The problem is not with that line of code but with a line before it.
Check to see if f_wb is what you expect.

Hope this helps!