AttributeError: ‘list’ object has no attribute ‘reshape’ error occurs when you try to operate the reshape() method on the list object, but it does not exist on the list. You can use the reshape() attribute on the numpy object.
Reproduce the error
main_list = [21, 11, 19, 46] main_list.rehsape(3, 2)
How to fix the error?
To fix the AttributeError: ‘list’ object has no attribute ‘reshape’ error, convert an input list to an array using numpy.array() method and then use the reshape() attribute on the numpy array object.
import numpy as np main_list = [21, 11, 19, 46] main_arr = np.array(main_list) print(main_arr.reshape(2, 2))
You can see that we get the output without errors because now we are calling the reshape() method on the numpy object, not the list object.