mindspore.Tensor.type_as

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

将Tensor的dtype转换成 other 的dtype。

参数:
  • other (Tensor) - 返回的Tensor和 other 具有相同的dtype。

返回:

Tensor,和 other 有相同的dtype。

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> from mindspore import Tensor
>>> x = Tensor([[1, 2], [3, 4]], dtype=mindspore.float32)
>>> y = Tensor([[1, 2], [3, 4]], dtype=mindspore.int32)
>>> x = x.type_as(y)
>>> print(x.dtype)
Int32