latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
Complex numbers
TensorPlay supports complex tensors — elements stored as a real and an imaginary part. Complex
dtypes are tensorplay.complex64 and tensorplay.complex128.
import tensorplay as tp
x = tp.tensor([1 + 2j, 3 - 4j])
print(x.dtype) # tensorplay.complex64
print(x.real) # the real part
print(x.imag) # the imaginary part
Creating complex tensors
tensorplay.complex builds a complex tensor from separate real and imaginary tensors, and
tensorplay.polar builds one from magnitude and angle:
re = tp.tensor([1.0, 3.0])
im = tp.tensor([2.0, -4.0])
z = tp.complex(re, im) # tensor([1.+2.j, 3.-4.j])
mag = tp.tensor([2.0, 1.0])
ang = tp.tensor([0.0, 1.5708])
p = tp.polar(mag, ang) # magnitude, angle
Reading and converting
tensorplay.real and tensorplay.imag extract the real and imaginary parts. conj returns
the complex conjugate and resolve_conj produces a tensor whose conjugation is applied;
view_as_real reinterprets a complex tensor as a float tensor with an extra trailing
dimension of size 2, while view_as_complex removes that pairing:
z = tp.tensor([1 + 2j, 3 + 4j])
print(tp.conj(z)) # [1.-2.j, 3.-4.j]
print(tp.view_as_real(z).shape) # (2, 2) — the trailing 2 is (real, imag)
tensorplay.is_complex reports whether a tensor has a complex dtype.
|
Constructs a complex tensor with its real part equal to |
|
Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value |
|
Returns a view of |
|
Returns a view of |
|
Returns True if the data type of |
|
Returns a view of |
|
Returns a new tensor with materialized conjugation if |
|
Returns a new tensor containing real values of the |
|
Returns a new tensor containing imaginary values of the |
Where to go next
Tensors — the full tensor API.
Type information — the limits of a complex dtype.
Help improve this page
Found an error, an unclear step, or a missing example?
Automatic Mixed Precision package - tensorplay.amp
tensorplay.amp provides convenience methods for mixed precision, where some operations use the tensorplay.float32 ( float ) datatype and other operations use lower precision floating point datatype ( lower_precision_fp )
Computation-graph visualization - tensorplay.utils.viz
Every result produced under autograd carries the recorded chain of operations behind it. make_dot walks that chain and renders it as a picture, so you can see exactly which operations produced a value before calling back

