Shortcuts

torch.meshgrid

torch.meshgrid(*tensors)[source]

Take NN tensors, each of which can be either scalar or 1-dimensional vector, and create NN N-dimensional grids, where the ii th grid is defined by expanding the ii 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 kk tensors of size (N1,),(N2,),,(Nk,)(N_1,), (N_2,), \ldots , (N_k,) , then the output would also have kk tensors, where all tensors are of size (N1,N2,,Nk)(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]])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources