Pytorch 网格

问题描述 投票:0回答:1

我目前正在使用 torch 1.12 来完成我的神经 A 星算法论文,我不太确定 meshgrid 的作用。例如为什么

x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])
torch.meshgrid(x, y)

返回

tensor([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
tensor([[4, 5, 6], [4, 5, 6], [4, 5, 6]])

而不是

tensor([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
tensor([[4, 4, 4], [5, 5, 5], [6, 6, 6]])
python pytorch tensor
1个回答
0
投票

这完全取决于您使用的索引模式:

ij
xy
(默认为
ij
):

>>> torch.meshgrid(x, y, indexing='xy')
(tensor([[1, 2, 3],
         [1, 2, 3],
         [1, 2, 3]]),
 tensor([[4, 4, 4],
         [5, 5, 5],
         [6, 6, 6]]))
© www.soinside.com 2019 - 2024. All rights reserved.