-1

我有一个形状为 (1120,1472,4) 的图像,我正在尝试将其更改为 (3000, 3000, 4) 我编写的代码是这样的。

pad_shape = (3000, 3000)
i = np.array('test.tif')
result = np.zeros(pad_shape,dtype=int)
result[:i.shape[0], :i.shape[1]] = i
print(result)

它生成

ValueError: could not broadcast input array from shape (1120, 1472, 4) into shape (3000, 3000)
4

1 回答 1

0

这里是答案

import numpy as np
from numpy import dtype

pad_shape = np.array((3000, 3000, 4))
i = np.zeros((1120, 1472, 4), dtype=np.int)

result = np.zeros(pad_shape, dtype=np.int)

x, y = 10, 10
shape = i.shape
print shape

rr = result[y:y+shape[0], x:x+shape[1]]
print rr

x 和 y 变量用于填充。由于填充而收到的错误。

于 2016-11-18T07:38:30.647 回答