mindspore.Tensor.type

View Source On Gitee
Tensor.type(dtype=None)[source]

Change the dtype of the Tensor to the dtype . Return the type if dtype is None .

Parameters

dtype (mindspore.dtype, optional) – The specified dtype of output tensor. Default: None.

Returns

Tensor or str. If dtype is None , return a str, which describes the dtype of Tensor. If dtype is not None , then return a Tensor, and the dtype of returned Tensor is dtype .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor
>>> x = Tensor([[1.2, 2], [3.4, 4]], dtype=mindspore.float32)
>>> print(x.type())
Float32
>>> print(x.type(dtype=mindspore.int32))
[[1 2]
 [3 4]]