Python Forum
'list' object has no attribute 'reshape'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'list' object has no attribute 'reshape'
#1
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'
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error "list object has no attribute transpose()" usercat123 4 4,186 Jan-28-2022, 12:01 PM
Last Post: usercat123
  Issues with Shape/Reshape for CNN moddy10 0 1,428 Oct-12-2021, 03:54 PM
Last Post: moddy10
  [pandas] How to reshape the list Mekala 6 7,249 Jul-26-2020, 12:49 AM
Last Post: Mekala
  cannot reshape array of size 0 into shape Roro 2 6,192 Jun-14-2020, 11:28 AM
Last Post: Roro
  reshape from 3D to 3D matrix paul18fr 0 1,716 Nov-12-2019, 11:26 AM
Last Post: paul18fr
  Simple numpy reshape error wih contour3D AdeIsHere 0 2,148 Sep-17-2019, 12:01 PM
Last Post: AdeIsHere
  Pandas to_csv in for loop AttributeError: 'tuple' object has no attribute 'to_csv' NSearch 9 16,755 Apr-22-2019, 05:05 PM
Last Post: Yoriz
  AttributeError: 'NoneType' object has no attribute 'all' synthex 2 5,207 Mar-07-2019, 11:11 AM
Last Post: synthex
  Please help with AttributeError: 'Netz' object has no attribute 'conv' DerBerliner 2 3,723 Feb-27-2019, 06:01 PM
Last Post: DerBerliner
  Generating a list to feed into a class object zizi 0 2,350 Nov-02-2018, 01:50 PM
Last Post: zizi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020