TypeErros: "float" object

hey :slight_smile:

I faced a problem during running the a code in C1_W1_Lab03:

def compute_cost (x,y,w,b):
m = len(x_train)
cost_sum = [0]
for i in range (m):
f_wb = wx[i] +b
cost = (y[i] - f_wb)^2
cost_sum = cost_sum + cost
total_cost = (1/2
return total_cost
x_train = np.array([1.0, 1.7, 2.0, 2.5, 3.0, 3.2])
y_train = np.array([250, 300, 480, 430, 630, 730,])

when I run this code, this error shows up about this part ( f_wb = wx[i] + b ):
f_wb = w
x[i] +b
TypeError: ‘float’ object is not subscriptable.

I think the “float” object refers to x_train variables. what should I do?

Hello @Elaheh_Khodadust,

It is crucial that you share the full error traceback (not just the last line of TypeError: ‘float’ object is not subscriptable.) so that based on which it is possible to provide you a different perspective or more understanding. Please share the full error traceback.


A post was split to a new topic: TypeError: ‘float’ object is not subscriptable