mindspore.ops.meshgrid
- mindspore.ops.meshgrid(*inputs, indexing='xy')[source]
Creates grids of coordinates specified by the 1D inputs。
Note
In graph mode, a tuple of N 1-D tensors and N should be greater than 1.
In pynative mode, a tuple of N 0-D or 1-D tensors and N should be greater than 0. The data type is Number.
In the 2-D case with inputs of length M and N, the outputs are of shape
for'xy'
indexing and for'ij'
indexing.In the 3-D case with inputs of length M, N and P, outputs are of shape
for'xy'
indexing and for'ij'
indexing.
- Parameters
inputs (Union[tuple[Tensor], list[Tensor]]) – Tuple of tensors or list of tensors.
- Keyword Arguments
indexing (str, optional) – Cartesian ('xy', default) or matrix ('ij') indexing of output. Valid options
'xy'
or'ij'
. Default'xy'
.- Returns
Tuple of N N-D tensors
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> x = mindspore.tensor([1, 2, 3, 4], mindspore.int32) >>> y = mindspore.tensor([5, 6, 7], mindspore.int32) >>> z = mindspore.tensor([8, 9, 0, 1, 2], mindspore.int32) >>> output = mindspore.ops.meshgrid(x, y, z, indexing='xy') >>> print(output) (Tensor(shape=[3, 4, 5], dtype=Int32, value= [[[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]], [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]], [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]]]), Tensor(shape=[3, 4, 5], dtype=Int32, value= [[[5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5], [5, 5, 5, 5, 5]], [[6, 6, 6, 6, 6], [6, 6, 6, 6, 6], [6, 6, 6, 6, 6], [6, 6, 6, 6, 6]], [[7, 7, 7, 7, 7], [7, 7, 7, 7, 7], [7, 7, 7, 7, 7], [7, 7, 7, 7, 7]]]), Tensor(shape=[3, 4, 5], dtype=Int32, value= [[[8, 9, 0, 1, 2], [8, 9, 0, 1, 2], [8, 9, 0, 1, 2], [8, 9, 0, 1, 2]], [[8, 9, 0, 1, 2], [8, 9, 0, 1, 2], [8, 9, 0, 1, 2], [8, 9, 0, 1, 2]], [[8, 9, 0, 1, 2], [8, 9, 0, 1, 2], [8, 9, 0, 1, 2], [8, 9, 0, 1, 2]]]))