to¶
- paddle.Tensor. to ( self, *args, **kwargs )
-
Performs Tensor dtype and/or device conversion. A paddle.dtype and place are inferred from the arguments of
self.to(*args, **kwargs)
.There are three ways to call to:to(dtype, blocking=True)
to(device, dtype=None, blocking=True)
to(other, blocking=True)
- Returns
-
self
- Return type
-
Tensor
Examples
>>> import paddle >>> tensorx = paddle.to_tensor([1,2,3]) >>> print(tensorx) Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True, [1, 2, 3]) >>> tensorx = tensorx.to("cpu") >>> print(tensorx.place) Place(cpu) >>> tensorx = tensorx.to("float32") >>> print(tensorx.dtype) paddle.float32 >>> tensorx = tensorx.to("gpu", "int16") >>> print(tensorx) Tensor(shape=[3], dtype=int16, place=Place(gpu:0), stop_gradient=True, [1, 2, 3]) >>> tensor2 = paddle.to_tensor([4,5,6]) >>> tensor2 Tensor(shape=[3], dtype=int64, place=Place(gpu:0), stop_gradient=True, [4, 5, 6]) >>> tensor2 = tensor2.to(tensorx) >>> print(tensor2) Tensor(shape=[3], dtype=int16, place=Place(gpu:0), stop_gradient=True, [4, 5, 6])