# tensorplay.as_tensor

Source: https://www.tensorplay.cn/docs/generated/tensorplay.as_tensor.html

# tensorplay.as_tensor

tensorplay.as_tensor(data, dtype=None, device=None)[[source]](../_modules/tensorplay.html#as_tensor)

Convert data into a tensor, sharing storage when possible.

If data is already a tensor with the requested dtype and device, it is
returned as-is (no copy).  Otherwise it is converted, mirroring
torch.as_tensor.

Parameters:

- data ( tensor , [list](https://docs.python.org/3/library/stdtypes.html#list) , or scalar ) – Initial data for the tensor.

- dtype ([tensorplay.DType](tensorplay.nn.functional.DType.html#tensorplay.nn.functional.DType), optional) – the desired data type of the returned tensor.

- device ([tensorplay.Device](tensorplay.Device.html#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
```
