title: How to flatten a 3d array to 1d array
body: <p>I need a 3d nested array. How can I flatten that to a 1d array? (Because of performance) I assume, that I need to multiply some stuff etc. but I'm not the greatest mathematician. 
  Thanks!</p>
  
  <pre class="lang-py prettyprint-override"><code>def imgRGB(im):
      width, height = im.size
  
      #create matrix
      matrix = []
      for i in range(height):
          matrix.append([[0,0,0] for _ in range(width)])
  
      #get the rgb values
      for x in range(width):
          for y in range(height):
              r,g,b = im.getpixel((x,y))
              matrix[y][x][0] = r
              matrix[y][x][1] = g
              matrix[y][x][2] = b
      return matrix
  </code></pre>
  
  <p>The pixel values will be compared to other RGB values to find the closest match.</p>
  
  <pre class="lang-py prettyprint-override"><code>def getNearestColor(rgb):
      a = []
      for i in range(len(rgbValues)):
          d = ((rgbValues[i][0]-rgb[0])*0.3)**2 + ((rgbValues[i][1]-rgb[1])*0.59)**2 + ((rgbValues[i][2]-rgb[2])*0.11)**2
          a.append(d)
      list.sort(a)
      return a[0]
  
  </code></pre>