oneflow.meshgrid(*tensors, indexing='ij')

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 \(i\) th input over dimensions defined by other inputs.

The interface is consistent with PyTorch. The documentation is referenced from:

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

  • indexing ((string, optional) – the indexing mode, either “xy” or “ij”, defaults to “ij”. If “ij” is selected, the dimensions are in the same order as the cardinality of the inputs. If “xy” is selected, the first dimension corresponds to the cardinality of the second input and the second dimension corresponds to the cardinality of the first input.


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

Return type

seq (sequence of Tensors)

For example:

>>> import numpy as np
>>> import oneflow as flow

>>> input1 = flow.tensor(np.array([2, 2, 3]), dtype=flow.float32)
>>> input2 = flow.tensor(np.array([4, 5, 6]), dtype=flow.float32)
>>> of_x, of_y = flow.meshgrid(input1, input2)
>>> of_x
tensor([[2., 2., 2.],
        [2., 2., 2.],
        [3., 3., 3.]], dtype=oneflow.float32)
>>> of_y
tensor([[4., 5., 6.],
        [4., 5., 6.],
        [4., 5., 6.]], dtype=oneflow.float32)