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 correct flow.dtype and flow.device, then input is returned. Otherwise, the returned tensor is a copy of input with the desired.

Parameters
Returns

A Tensor.

Return type

oneflow.Tensor

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