mindspore.Tensor.view_as

查看源文件
mindspore.Tensor.view_as(other)[源代码]

根据 other 的shape改变原Tensor的shape。

参数:
  • other (Tensor) - 返回Tensor的shape与 other 的shape一致。

返回:

Tensor,和 other 具有相同的shape。

异常:
  • TypeError - other 不是Tensor。

支持平台:

Ascend GPU CPU

样例:

>>> from mindspore import Tensor
>>> from mindspore import dtype as mstype
>>> a = Tensor([[1, 2, 3], [2, 3, 4]], mstype.float32)
>>> b = Tensor([1, 1, 1, 1, 1, 1], mstype.float32)
>>> output = a.view_as(b)
>>> print(output)
[1. 2. 3. 2. 3. 4.]