cast¶
- paddle. cast ( x, dtype ) [source]
-
Take in the Tensor
x
withx.dtype
and cast it to the output withdtype
. It’s meaningless if the output dtype equals the input dtype, but it’s fine if you do so.- Parameters
-
x (Tensor) – An input N-D Tensor with data type bool, float16, float32, float64, int32, int64, uint8.
dtype (np.dtype|str) – Data type of the output: bool, float16, float32, float64, int8, int32, int64, uint8.
- Returns
-
Tensor, A Tensor with the same shape as input’s.
Examples
>>> import paddle >>> x = paddle.to_tensor([2, 3, 4], 'float64') >>> y = paddle.cast(x, 'uint8')