TensorPlay

Latest development documentation · Updated 2026-09-08. A documentation snapshot for package 1.0.0.dev20260909 is not available.

On this page

tensorplay.as_tensor

tensorplay.as_tensor(data, dtype=None, device=None)[source]

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 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

Search documentation

Search all 1,743 documentation pages.

Keyboard shortcuts

Global

  • /Focus search
  • ?This dialog
  • ,Open settings
  • jAI assistant

Search

  • Navigate results
  • Open result
  • escClose

Package

  • mMain information
  • dDocs
  • .Code
  • -Changelog
  • tTimeline
  • sStats
  • vVersions