Python Forum

Full Version: 'list' object has no attribute 'reshape'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'
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.