oneflow.cast¶
-
oneflow.
cast
()¶ The operation takes input tensor x and casts it to the output with dtype
- Parameters
x (oneflow.Tensor) – A Tensor
dtype (flow.dtype) – Data type of the output tensor
- Returns
A Tensor with specific dtype.
- Return type
For example:
>>> import oneflow as flow >>> import numpy as np >>> np_arr = np.random.randn(2, 3, 4, 5).astype(np.float32) >>> input = flow.tensor(np_arr, dtype=flow.float32) >>> output = flow.cast(input, flow.int8) >>> np.array_equal(output.numpy(), np_arr.astype(np.int8)) True