tensorplay.as_tensor
- tensorplay.as_tensor(data, dtype=None, device=None)[source]
Convert
datainto a tensor, sharing storage when possible.If
datais already a tensor with the requested dtype and device, it is returned as-is (no copy). Otherwise it is converted to the requested dtype and device.- Parameters:
data (tensor, list, or scalar) – Initial data for the tensor.
dtype (
tensorplay.DType, optional) – the desired data type of the returned tensor.device (
tensorplay.Device, str, optional) – the device of the constructed tensor.
Example:
>>> x = tensorplay.tensor([1.0, 2.0]) >>> tensorplay.as_tensor(x) is x True >>> tensorplay.as_tensor([0, 1, 2], dtype=tensorplay.int64).dtype == tensorplay.int64 True

