mindspore.ops.meshgrid

mindspore.ops.meshgrid(inputs, indexing='xy')[源代码]

从给定的Tensor生成网格矩阵。

给定N个一维Tensor,对每个Tensor做扩张操作,返回N个N维的Tensor。

参数:

  • inputs (Union[tuple]) - N个一维Tensor。输入的长度应大于1。数据类型为Number。

  • indexing (str, optional) - ‘xy’或’ij’。以笛卡尔坐标’xy’或者矩阵’ij’索引作为输出。以长度为 MN 的二维输入,取值为’xy’时,输出的shape为 \((N, M)\) ,取值为’ij’时,输出的shape为 \((M, N)\) 。以长度为 M , NP 的三维输入,取值为’xy’时,输出的shape为 \((N, M, P)\) ,取值为’ij’时,输出的shape为 \((M, N, P)\) 。默认值:’xy’。

返回:

Tensor,N个N维tensor对象的元组。数据类型与输入相同。

异常:

  • TypeError - indexing 不是str或 inputs 不是元组。

  • ValueError - indexing 的取值既不是’xy’也不是’ij’。

支持平台:

Ascend CPU GPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor
>>> import mindspore.ops as 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))
>>> inputs = (x, y, z)
>>> output = ops.meshgrid(inputs, 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]]]))