mindspore.ops.meshgrid
- mindspore.ops.meshgrid(*inputs, indexing='xy')[source]
Generates coordinate matrices from given coordinate tensors.
Given N one-dimensional coordinate tensors, returns a tuple outputs of N N-D coordinate tensors for evaluating expressions on an N-D grid.
- Parameters
inputs (List[Tensor]) – List of 1-D tensors. The length of inputs should be greater than 1. 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, the outputs are of shape \((N, M)\) for'xy'
indexing and \((M, N)\) for'ij'
indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape \((N, M, P)\) for'xy'
indexing and \((M, N, P)\) for'ij'
indexing. Default:'xy'
.- Returns
Tensors, a Tuple of N N-D Tensor objects. The data type is the same with the Inputs.
- Raises
TypeError – If indexing is not a str or inputs is not a tuple.
ValueError – If indexing is neither
'xy'
nor'ij'
.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> from mindspore import ops >>> x = Tensor(np.array([1, 2, 3, 4]).astype(np.int32)) >>> y = Tensor(np.array([5, 6, 7]).astype(np.int32)) >>> z = Tensor(np.array([8, 9, 0, 1, 2]).astype(np.int32)) >>> output = 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]]]))