Tensor¤
The core Tensor class wraps a NumPy (or CuPy) array and tracks gradients for backpropagation.
Constructor¤
Properties¤
shape,ndim,dtype- standard array propertiesT- transpose (swaps last two dims)device-"cpu"or"cuda"size(dim=None)- total elements or size of a specific dimension
Static Constructors¤
Tensor.zeros(2, 3)
Tensor.ones(2, 3, requires_grad=True)
Tensor.randn(4, 5, device="cuda")
Tensor.eye(3)
Arithmetic¤
+, -, *, /, ** with broadcasting. Right-hand variants (5.0 + tensor) supported. @ for matrix multiplication.
Reductions¤
sum(axis, keepdims),mean(axis, keepdims)max(axis, keepdims),min(axis, keepdims)var(axis, keepdims),std(axis, keepdims)
Shape Operations¤
reshape(*shape),transpose(dim0, dim1)squeeze(axis),unsqueeze(axis)__getitem__for indexing/slicing
Elementwise¤
exp(),log(),abs(),clamp(min_val, max_val)
Autograd¤
backward()- reverse-mode autodiff (scalar tensors only)zero_grad(),detach(),clone()
Device Transfer¤
no_grad Context Manager¤
Disable gradient tracking for inference: