我正在try 将一个稀疏的数组图像reshape for each 单元16x16个元素的网格图像.我认为
grid_image = image.reshape((h//16, w//16, -1))
应该能行得通.在下面的示例中,GRID_IMAGE具有(1,2,256)形状.然而,当我将元素GRID_IMAGE[0,0]与图像[:16,:16].ravel()中的元素进行比较时,它们并不相同.下面的代码显示为假.我的逻辑一定是错的,但我不知道在哪里.有什么帮助吗?
import numpy as np
h,w = 16,32
image = np.random.rand(h, w)
grid_image = image.reshape((h//16, w//16, -1))
print((image[:16, :16].ravel() == grid_image[0,0]).all())