mindspore.ops.meshgrid

查看源文件
mindspore.ops.meshgrid(*inputs, indexing='xy')[源代码]

从一维输入生成多维坐标网格。

说明

  • graph mode下的 inputs 为N个一维tensor,N应大于1。

  • pynative mode下的 inputs 为N个零维或一维tensor,N应大于0。数据类型为Number。

  • 对于长度为 MN 的二维输入,取值为 'xy' 时,输出的shape为 (N,M) ,取值为 'ij' 时,输出的shape为 (M,N)

  • 对于长度为 MNP 的三维输入,取值为 'xy' 时,输出的shape为 (N,M,P) ,取值为 'ij' 时,输出的shape为 (M,N,P)

参数:
  • inputs (Union[tuple[Tensor], list[Tensor]]) - 输入tensors。

关键字参数:
  • indexing (str, 可选) - 输出的网格矩阵的size。可选 'xy''ij' 。默认 'xy'

返回:

由N个N维tensor组成的元组。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> x = mindspore.tensor(np.array([1, 2, 3, 4]).astype(np.int32))
>>> y = mindspore.tensor(np.array([5, 6, 7]).astype(np.int32))
>>> z = mindspore.tensor(np.array([8, 9, 0, 1, 2]).astype(np.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]]]))