Python Forum
'list' object has no attribute 'reshape' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: 'list' object has no attribute 'reshape' (/thread-13879.html)



'list' object has no attribute 'reshape' - SamSoftwareLtd - Nov-04-2018

Hi All,

I've just joined this forum, also new to Python, with background in other languages.

I've been trying a small piece of code below using jupyter ipython in notebooks.azure.com, the error is coming from the last call for np.reshape function which I'd used it previously with no problems, so your comment/tips would be much appreciated, many thanks:

import numpy as np
import pandas as pd

file = open("/home/nbuser/F-F_Research_Data_Factors_StrippedandCleaned.txt","r")
data = file.readlines()

f=[]
index=[]

for i in range(1,np.size(data)):
    t= data[i].split()
    index.append(int(t[0]))
    for j in range(1,5):
        k=float(t[j])
        f.append(k/100)
n=len(f)
f1=np.reshape(f,[n/4,4])
f1
and get the below:

Error:
Attribute Error: 'list' object has no attribute 'reshape'



RE: 'list' object has no attribute 'reshape' - stullis - Nov-04-2018

np.reshape ultimately calls up the reshape method of the object passed to it. So, it's trying to call list.reshape() which doesn't exist. The documentation suggests that it needs an array instead of a list to effectively work.