Take N tensors, each of which can be either scalar or 1-dimensional vector, and create N N-dimensional grids, where the i th grid is defined by expanding the ii th input over dimensions defined by other inputs.
공식 설명은 위와 같다.
각각의 원소가 scalar 또는 1 dimensional vector인 N 개의 tensor를 받아서 N개의 N dimensional grids를 만든다. i번째 grid는 i번째 input을 다른 input으로 정의된 차원만큼 확장한 것이다.
>>> x = torch.tensor([1, 2])
>>> y = torch.tensor([3, 4, 5])
>>> z = torch.tensro([6, 7, 8, 9])
>>> grid_x, grid_y, grid_z = torch.meshgrid(x,y,z)
>>> print(grid_x.shape)
torch.Size([2, 3, 4])
>>> print(grid_x)
tensor([[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],
[[2, 2, 2, 2],
[2, 2, 2, 2],
[2, 2, 2, 2]]])
>>> print(grid_y.shape)
torch.Size([2, 3, 4])
>>> print(grid_y)
tensor([[[3, 3, 3, 3],
[4, 4, 4, 4],
[5, 5, 5, 5]],
[[3, 3, 3, 3],
[4, 4, 4, 4],
[5, 5, 5, 5]]])
>>> print(grid_z.shape)
torch.Size([2, 3, 4])
>>> print(grid_z)
tensor([[[6, 7, 8, 9],
[6, 7, 8, 9],
[6, 7, 8, 9]],
[[6, 7, 8, 9],
[6, 7, 8, 9],
[6, 7, 8, 9]]])