我想按照这里的建议对 numpy 数组重新取样 Resampling a numpy array representing an image然而,这种重采样将通过一个因素来实现,即
x = np.arange(9).reshape(3,3)
print scipy.ndimage.zoom(x, 2, order=1)
将创建 (6,6) 的形状,但我如何才能将数组重新采样到 (4,6)、(6,8) 或 (6,10) 形状内的最佳近似值?
最佳答案
不是将单个数字传递给 zoom
参数,而是给出一个序列:
scipy.ndimage.zoom(x, zoom=(1.5, 2.), order=1)
#array([[0, 0, 1, 1, 2, 2],
# [2, 2, 3, 3, 4, 4],
# [4, 4, 5, 5, 6, 6],
# [6, 6, 7, 7, 8, 8]])
使用序列 (2., 2.75)
和 (2., 3.5)
你会得到形状为 (6, 8)
的输出数组code> 和 (6, 10)
。
关于python - 重新采样并调整 numpy 数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23424716/