-1

모양이 이미지 (1120,1472,4)이고,이를 3000, 3000, 4) 내가 작성한 코드는 이와 같습니다.ValueError : 모양 (1120,1472,4)에서 입력 배열을 모양 (3000,3000)으로 브로드 캐스팅 할 수 없습니다.

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) 
+0

1120 * 1472! = 3000 * 3000, "모양 변경"이란 무엇입니까? 새로운 어레이에는 더 많은 요소가있을 것입니다. –

+1

이것은 단순한 오타입니다. pad_shape에서 4를 놓친 경우 –

답변

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 변수의 응답이다. 패딩으로 인해받은 오류입니다.

+0

OP가 결과 모양에서 4를 놓 쳤기 때문에 오류가 발생했습니다. –

+0

그러나 x와 y 변수에주의하십시오. 이미지 경계를 넘으면 오류가 다시 발생합니다. –

+0

OP가 아닌 이미지의 경계에 대한 오류가 명확합니다. 내 코드를 테스트하면 P.Camilleri –