AttributeError numpy ndarray object has no attribute append

0 votes

x_train=[]
y_train=[]
for i in range(8,64):
    x_train.append(trs[i-8:i,0])
    y_train.append(trs[i,0])
    x_train,y_train=np.array(x_train),np.array(y_train)
    
    x_train=np.reshape(x_train,(x_train.shape[0],x_train.shape[1],1))

AttributeError                            Traceback (most recent call last)
<ipython-input-24-624f0e25b1ac> in <module>
      2 y_train=[]
      3 for i in range(8,64):
----> 4     x_train.append(trs[i-8:i,0])
      5     y_train.append(trs[i,0])
      6     x_train,y_train=np.array(x_train),np.array(y_train)

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Aug 10, 2020 in Python by Nilesh
• 140 points
2,938 views

Hello @Nilesh,

What is trs in your snippet??

Means what is trs[i-8:i,0]?

1 answer to this question.

0 votes

Hi@Nilesh,

You created two empty lists. And in the for loop, you tried to append values in your list. But in the last part, you tried to convert your list into NumPy array using the same variable name. So I suggest you change your variable name as given below.

x_train=[]
y_train=[]
for i in range(8,64):
    x_train.append(trs[i-8:i,0])
    y_train.append(trs[i,0])
    X_train,Y_train=np.array(x_train),np.array(y_train)

Now try to run your code once, it will work.

answered Aug 11, 2020 by MD
• 95,440 points

Related Questions In Python

0 votes
1 answer

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Hi@Nilesh, You have created two empty lists. And ...READ MORE

answered Aug 11, 2020 in Python by MD
• 95,440 points
6,115 views
0 votes
1 answer

AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'

Hi@akhtar, I think numpy version is not compatible ...READ MORE

answered Apr 13, 2020 in Python by MD
• 95,440 points
13,833 views
+1 vote
1 answer

'numpy.ndarray' object has no attribute 'append'

Hi@Noman, You created two empty list. And in ...READ MORE

answered May 17, 2020 in Python by MD
• 95,440 points
7,748 views
0 votes
0 answers

AttributeError: 'numpy.int32' object has no attribute 'map'

can any one suggest solution data['isLarge'] = data.size.map({'small' ...READ MORE

Sep 5, 2020 in Python by Mohammed
• 120 points
4,122 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,067 views
0 votes
1 answer
0 votes
3 answers

AttributeError: 'numpy.ndarray' object has no attribute 'append'

for root, dirs, files in os.walk(directory): ...READ MORE

answered Dec 12, 2020 in Python by Rajiv
• 8,910 points
52,166 views
+1 vote
1 answer

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Hi, You created two empty list. And in ...READ MORE

answered May 17, 2020 in Python by MD
• 95,440 points
5,085 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP