我在Python中有一个2D numpy数组,对应于在for循环中计算的图像。数组的大小为Nx40。我希望在每个循环步骤中将初始数组分割成大小为40x40(大约)的矩形数组。如果N不能被40整除,则最后一个图像应包含除法的余数。因此,例如87x40应为(40x40和47x40)。到目前为止,我所做的是:
div_num = spec.shape[0] / spec.shape[1]
remaining = spec.shape[0] % spec.shape[1]
lista = []
for i in range(1, div_num+1):
img = spec[((i-1)*40):(i*40)][0:40]
lista.append(img)
如何在最后一张图片中添加剩余的行?
img
。 - Aristotelis