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
4,611 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, 2020 by MD
• 95,300 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, 2020 in Python by MD
• 95,300 points
1,561 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,300 points
6,699 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,300 points
6,252 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
1,574 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,369 views
0 votes
0 answers
0 votes
3 answers

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

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

answered Dec 11, 2020 in Python by Rajiv
• 8,890 points
41,410 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,300 points
3,564 views