我目前正在使用 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]])
这完全取决于您使用的索引模式:
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]]))