mindspore.Tensor.short

mindspore.Tensor.short()[源代码]

将输入Tensor转换为 int16 类型并返回一个拷贝,与 self.astype(mstype.int16) 等价,其中Tensor中的值为浮点数时,则会丢弃小数部分,具体请参考 mindspore.Tensor.astype()

返回:

Tensor,其数据类型为 int16

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore as ms
>>> import numpy as np
>>> x = ms.Tensor(np.array([1,2,3,4,5]), ms.int32)
>>> output = x.short()
>>> output
Tensor(shape=[5], dtype=Int16, value= [1, 2, 3, 4, 5])