mindspore.ops.Meshgrid

查看源文件
class mindspore.ops.Meshgrid(indexing='xy')[源代码]

从给定的Tensor生成网格矩阵。给定N个一维Tensor,对每个Tensor做扩张操作,返回N个N维的Tensor。

更多参考详见 mindspore.ops.meshgrid()

参数:
  • indexing (str, 可选) - 以笛卡尔坐标 'xy' 或者矩阵 'ij' 索引作为输出。对于长度为 MN 的二维输入,取值为 'xy' 时,输出的shape为 \((N, M)\) ,取值为 'ij' 时,输出的shape为 \((M, N)\) 。对于长度为 MNP 的三维输入,取值为 'xy' 时,输出的shape为 \((N, M, P)\) ,取值为 'ij' 时,输出的shape为 \((M, N, P)\) 。默认值: 'xy'

输入:
  • inputs (Union(tuple[Tensor], list[Tensor])) - 静态图下为N个一维Tensor,输入的Tensor个数应大于1。动态图下为N个零维或一维Tensor,输入的Tensor个数应大于0。数据类型为Number。

输出:

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

支持平台:

Ascend GPU CPU

样例:

>>> import numpy as np
>>> from mindspore import Tensor, 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)
>>> meshgrid = ops.Meshgrid(indexing='xy')
>>> output = meshgrid(inputs)
>>> 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]]]))