title: Python - AttributeError: 'numpy.ndarray' object has no attribute 'append'
body: <p>This is related to my question, <a href="https://stackoverflow.com/questions/42941668/valueerror-could-not-broadcast-input-array-from-shape-22500-3-into-shape-1">here</a>.</p>
  
  <p>I now have the updated code as follows:</p>
  
  <pre><code>import numpy as np
  import _pickle as cPickle
  from PIL import Image
  import sys,os
  
  pixels = []
  labels = []
  traindata = []
  i = 0
  
  directory = 'C:\\Users\\abc\\Desktop\\Testing\\images'
  for root, dirs, files in os.walk(directory):
      for file in files:
          floc = file
          im = Image.open(str(directory) + '\\' + floc)
          pix = np.array(im.getdata())
          pixels.append(pix)
          labels.append(1)
          pixels = np.array(pixels)
          labels = np.array(labels)
          traindata.append(pixels)
          traindata.append(labels)
          traindata = np.array([traindata[i][i],traindata[1]], dtype=object)
          i = i + 1
  
  # do the same for validation and test data
  # put all data and labels into 'data' array
  cPickle.dump(traindata,open('data.pickle','wb'))
  
  FILE = open("data.pickle", 'rb')
  content = cPickle.load(FILE)
  print (content)
  </code></pre>
  
  <p>When having only one image, the code runs fine. But, when I add another image or more, I get the following:</p>
  
  <pre><code>Traceback (most recent call last):
    File "pickle_data.py", line 17, in &lt;module&gt;
      pixels.append((pix))
  AttributeError: 'numpy.ndarray' object has no attribute 'append'
  </code></pre>
  
  <p>How can I solve this issue?</p>
  
  <p>Thanks.</p>