1. 程式人生 > 其它 >【debug】ValueError: all the input arrays must have same number of dimensions 解決

【debug】ValueError: all the input arrays must have same number of dimensions 解決

技術標籤:pytorchpython

使用

# T是個整數tensor
np.concatenate((align[1:],T.cpu().numpy()), axis=0)

報錯ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 0 dimension(s)
檢視align[1:]及T.cpu().numpy()的shape如下:
在這裡插入圖片描述
在這裡插入圖片描述
T.cpu().numpy()少了一維。更改如下

np.concatenate((align[1:],[T.cpu().numpy()]), axis=0)
#或
np.concatenate((align[1:],T.cpu().numpy().reshape(-1)), axis=0)