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 in Python by Nilesh
• 140 points
367 views

1 answer to this question.

0 votes

Hi@Nilesh,

You have 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 10 by MD
• 56,480 points

Related Questions In Python

0 votes
1 answer

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

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

answered Aug 10 in Python by MD
• 56,480 points
140 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 in Python by MD
• 56,480 points
1,378 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 in Python by MD
• 56,480 points
2,543 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 in Python by Mohammed
• 120 points
67 views
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,356 views
0 votes
0 answers
0 votes
1 answer
+1 vote
1 answer