Numpy flatten RGB image array

Try this:

d1, d2, d3, d4 = x_data.shape

then using numpy.reshape()

x_data_reshaped = x_data.reshape((d1, d2*d3*d4))

or

x_data_reshaped = x_data.reshape((d1, -1))

(Numpy infers the the value instead of -1 from original length and defined dimension d1)


Apply the numpy method reshape() after applying flatten() to the flattened array:

  x_data = np.array( [np.array(cv2.imread(imagePath[i])) for i in range(len(imagePath))] )

  pixels = x_data.flatten().reshape(1000, 12288)
  print pixels.shape