cast
- paddle. cast ( x: Tensor, dtype: DTypeLike ) Tensor [source]
-
Take in the Tensor
xwithx.dtypeand 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.The following picture shows an example where a tensor of type float64 is cast to a tensor of type uint8.
- Parameters
-
x (Tensor) – An input N-D Tensor with data type bool, float16, float32, float64, int32, int64, uint8.
dtype (paddle.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')
