mindspore.mint.meshgrid

查看源文件
mindspore.mint.meshgrid(*tensors, indexing=None)[源代码]

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

输入N个一维tensor,对每个tensor做扩张操作,返回N个N维的tensor。

警告

  • 这是一个实验性API,后续可能修改或删除。

  • Graph mode,dynamic shape场景下:仅支持输入N个一维tensor,N > 1。

参数:
  • tensors (Union(tuple[Tensor], list[Tensor])) - N个零维或一维tensor,N > 0, tensor的数据类型为Number。

关键字参数:
  • indexing (str, 可选) - 影响输出的网格矩阵的size。可选值为: 'xy''ij' 。对于长度为 MN 的二维输入,取值为 'xy' 时,输出的shape为 \((N, M)\) ;取值为 'ij' 时,输出的shape为 \((M, N)\) 。以长度为 MNP 的三维输入,取值为 'xy' 时,输出的shape为 \((N, M, P)\) ;取值为 'ij' 时,输出的shape为 \((M, N, P)\) 。默认 None ,此时等价于取值为 'ij'

返回:

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

异常:
  • ValueError - indexing 的取值既不是 'xy' 也不是 'ij'

支持平台:

Ascend

样例:

>>> 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]]]))