title: Concatenate numpy arrays in for loop
body: <p>I've split an image up into 16 figures to plot regression and now I want to join it back together into one image. </p>
  
  <p>I've written a for loop to do this but I'm having trouble understanding the advice from <a href="https://stackoverflow.com/questions/22662996/merge-numpy-arrays-returned-from-loop">previous questions</a> and where I'm going wrong. Please could someone explain why my input arrays do not have the same number of dimensions.</p>
  
  <pre><code>from scipy import interpolate
  
  
  allArrays = np.array([])
  for i in range(len(a)):
  
      fig = plt.figure()
      ax = fig.add_axes([0.,0.,1.,1.])
  
  
      if np.amax(a[i]) &gt; 0:
          x, y = np.where(a[i]&gt;0)
          f = interpolate.interp1d(y, x)
          xnew = np.linspace(min(y), max(y), num=40)
          ynew = f(xnew)   
          plt.plot(xnew, ynew, '-')
          plt.ylim(256, 0)
          plt.xlim(0,256)
  
          fig.canvas.draw()
          X = np.array(fig.canvas.renderer._renderer)
          myArray = color.rgb2gray(X)
          print(myArray.shape)
          allArrays = np.concatenate([allArrays, myArray])
          print(allArrays.shape)
  
      else:
  
          plt.xlim(0,256)
          plt.ylim(0,256)
          fig.canvas.draw()
          X = np.array(fig.canvas.renderer._renderer)
          myArray = color.rgb2gray(X)
          print(myArray.shape)
          allArrays = np.concatenate([allArrays, myArray])
          print(allArrays.shape)
  
  
  
  
      i += 1  
  </code></pre>
  
  <p>Output: myArray.shape (480, 640)</p>
  
  <p>Error message: all the input arrays must have same number of dimensions  </p>
  
  <p>I'm sure it's really simple but I can't figure it out. Thanks.</p>