astype

paddle.Tensor. astype ( self, dtype )

Cast a Tensor to a specified data type.

Parameters

dtype – The target data type.

Returns

a new Tensor with target dtype

Return type

Tensor

Examples

>>> import paddle
>>> import numpy as np

>>> original_tensor = paddle.ones([2, 2])
>>> print("original tensor's dtype is: {}".format(original_tensor.dtype))
original tensor's dtype is: paddle.float32
>>> new_tensor = original_tensor.astype('float32')
>>> print("new tensor's dtype is: {}".format(new_tensor.dtype))
new tensor's dtype is: paddle.float32