oneflow.Tensor.to¶
-
Tensor.
to
(*args, **kwargs)¶ - Performs Tensor dtype and/or device conversion.
A flow.dtype and flow.device are inferred from the arguments of input.to(*args, **kwargs).
Note
If the
input
Tensor already has the correctflow.dtype
andflow.device
, theninput
is returned. Otherwise, the returned tensor is a copy ofinput
with the desired.- Parameters
input (oneflow.Tensor) – An input tensor.
*args (oneflow.Tensor or oneflow.device or oneflow.dtype) – Positional arguments
**kwargs (oneflow.device or oneflow.dtype) – Key-value arguments
- Returns
A Tensor.
- Return type
For example:
>>> import numpy as np >>> import oneflow as flow >>> arr = np.random.randint(1, 9, size=(1, 2, 3, 4)) >>> input = flow.Tensor(arr) >>> output = input.to(dtype=flow.float32) >>> np.array_equal(arr.astype(np.float32), output.numpy()) True