Tensor Creation
Overview
- Use tensor, zeros, ones, eye, arange, linspace, geomspace, and related factories to create dense arrays.
- The Tensor class is the common runtime object for dense numerical data, while AnyTensor covers Tensor and GradTensor together.
- Complex arrays, Float16/BFloat16 buffers, and TensorCreateOptions support newer numerical workflows introduced in v1.0.0.
Complex
Complex number types and typed arrays for complex64/complex128 support.
Complex64Array
Complex64 typed array — each element is two float32 values (real, imag).
Complex128Array
Complex128 typed array — each element is two float64 values (real, imag).
BFloat16Array
Software BFloat16 (Brain Floating Point) array.
Float16Array
Software IEEE 754 half-precision floating-point array.
Tensor
Multi-dimensional array (tensor) with typed storage.
Range.
Fill with a scalar value.
Identity matrix.
Flatten to 1D.
full is exported by deepbox/ndarray.
Gather values along an axis specified by indices.
Numbers spaced evenly on a log scale (geometric progression).
Evenly spaced numbers over a specified interval.
Numbers spaced evenly on a log scale.
All ones.
Return a tensor filled with random samples from a standard normal distribution.
Change shape (view) without copying.
Slice a tensor.
tensor is exported by deepbox/ndarray.
Transpose tensor dimensions.
All zeros.
Remove single-dimensional entries from the shape.
Expand the shape by inserting a new axis.
import { Complex, arange, eye, reshape, tensor, zeros,} from "deepbox/ndarray";const a = tensor([[1, 2], [3, 4]]);const b = zeros([2, 2]);const c = reshape(arange(0, 6), [2, 3]);const i = eye(3);const z = new Complex(1, -2);console.log(a.shape, b.dtype, c.toString(), i.toString(), z.toString());