我有 1,000 张 RGB 图像 (64X64),我想将其转换为 (m, n) 数组。
我用这个:
import numpy as np
from skdata.mnist.views import OfficialImageClassification
from matplotlib import pyplot as plt
from PIL import Image
import glob
import cv2
x_data = np.array( [np.array(cv2.imread(imagePath[i])) for i in range(len(imagePath))] )
print x_data.shape
这给了我:(1000, 64, 64, 3)
现在如果我这样做:
pixels = x_data.flatten()
print pixels.shape
我得到:(12288000,)
但是,我需要一个具有这些维度的数组:(1000, 12288)
我怎样才能做到这一点?
最佳答案
在将 flatten()
应用于展平数组后,应用 numpy 方法 reshape()
:
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
关于python - Numpy 展平 RGB 图像数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36967920/