mindspore.mint.meshgrid
- mindspore.mint.meshgrid(*tensors, indexing=None)[source]
Generate coordinate matrices from given coordinate tensors.
- Given N 1-D coordinate tensors, returns a tuple outputs of N N-D
coordinate tensors for evaluating expressions on an N-D grid.
Warning
This is an experimental API that is subject to change or deletion.
Graph mode, dynamic shape scenario: Only supports input of N 1-D tensors, where N > 1.
- Parameters
tensors (Union(tuple[Tensor], list[Tensor])) – In GRAPH_MODE, a tuple of N 1-D Tensor objects and the length of input should be greater than 1. In PYNATIVE_MODE, a tuple of N 0-D or 1-D Tensor objects and the length of input should be greater than 0. The data type is Number.
- Keyword Arguments
indexing (str, optional) – Cartesian ('xy', default) or matrix ('ij') indexing of output. Valid options: xy' or
'ij'. In the 2-D case with inputs of length M and N, for'xy'indexing, the shape of outputs is \((N, M)\) for'ij'indexing, the shape of outputs is \((M, N)\). In the 3-D case with inputs of length M, N and P, for'xy'indexing, the shape of outputs is \((N, M, P)\) and for'ij'indexing, the shape of outputs is \((M, N, P)\). DefaultNone, which is equivalent to the value'ij'.- Returns
Tensors, a Tuple of N N-D Tensor objects. The data type is the same with the Inputs.
- Raises
ValueError – If indexing is neither
'xy'nor'ij'.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> x = mindspore.tensor([1, 2, 3, 4]) >>> y = mindspore.tensor([5, 6, 7]) >>> z = mindspore.tensor([8, 9, 0, 1, 2]) >>> mindspore.mint.meshgrid(x, y, z, indexing='xy') (Tensor(shape=[3, 4, 5], dtype=Int64, 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=Int64, 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=Int64, 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]]]))