pytorch / 1.8.0 / generated / torch.meshgrid.html /

torch.meshgrid

torch.meshgrid(*tensors) [source]

Take N N tensors, each of which can be either scalar or 1-dimensional vector, and create N N N-dimensional grids, where the i i th grid is defined by expanding the i i th input over dimensions defined by other inputs.

Parameters

tensors (list of Tensor) – list of scalars or 1 dimensional tensors. Scalars will be treated as tensors of size ( 1 , ) (1,) automatically

Returns

If the input has k k tensors of size ( N 1 , ) , ( N 2 , ) , , ( N k , ) (N_1,), (N_2,), \ldots , (N_k,) , then the output would also have k k tensors, where all tensors are of size ( N 1 , N 2 , , N k ) (N_1, N_2, \ldots , N_k) .

Return type

seq (sequence of Tensors)

Example:

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

© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.meshgrid.html