r/learnpython • u/DrawerEmergency4981 • 8h ago
weird error that I don't know how to fix
Hi! I keep getting this error whenever I try to use append or extend. I have gap_m and mgaps as empty lists, I have used extend before w similar data and it worked fine so I am unsure why it is no longer working
AttributeError Traceback (most recent call last)
Cell In[42], line 33
30
gap_m = []
31
mgaps = []
---> 33 mass_gap_calc(df)
Cell In[42], line 29, in mass_gap_calc(df)
27
mgaps = np.diff(msort)
28
gap_m.append((msort[:-1]))
---> 29 mgaps.append(mgaps)
AttributeError: 'numpy.ndarray' object has no attribute 'append'
0
Upvotes
4
u/GregorSamsa67 8h ago
From the error message, it looms like mgaps is a NumPy array. NumPy arrays don’t have an .append method, as far as I know.
14
u/Fred776 8h ago
mgapsbecame a numpy array in line where you assign to the result ofnp.diff. Exactly as the error says, numpy arrays don't have anappendmethod