Error: list object has no attribute shape

Just trying to run the week 1 optional lab code of cost function in a jupyter notebook where this error pops out “list” object has no shape attribute.
AttributeError Traceback (most recent call last)
Cell In[52], line 2
1 plt.close(‘all’)
----> 2 fig, ax, dyn_items = plt_stationary(x_train, y_train)
3 updater = plt_update_onclick(fig, ax, x_train, y_train, dyn_items)

File ~\OneDrive\Desktop\Jupyter\lab_ml\lab_utils_uni.py:124, in plt_stationary(x_train, y_train)
122 for i in range(tmp_w.shape[0]):
123 for j in range(tmp_w.shape[1]):
→ 124 z[i,j] = compute_cost(x_train, y_train, tmp_w[i][j], tmp_b[i][j] )
125 if z[i,j] == 0: z[i,j] = 1e-6
127 w0=200;b=-100 #initial point

File ~\OneDrive\Desktop\Jupyter\lab_ml\lab_utils_common.py:79, in compute_cost(X, y, w, b)
68 def compute_cost(X, y, w, b):
69 “”"
70 compute cost
71 Args:
(…)
77 cost (scalar) : cost
78 “”"
—> 79 m = X.shape[0]
80 cost = 0.0
81 for i in range(m):

AttributeError: ‘list’ object has no attribute ‘shape’
please help asap

X.shape is a method of numpy arrays not plain python lists, you can convert a list to a numpy list with numpy.asarray(list) or to find the number of elements in a python list you can use the method len(list).

Then should I use m= len(X) instead.

No. Actually, X is ndarray and has a shape attribute. But I guess you are changing its type. In optional labs, you just need to run all the cells and see how they are working, not change anything. Are you sure you are not making any changes?

Nope, I was doing On another jupyter notebook not in optional labs and m=len(x) worked well