Expand Dims
Shippingtensor_expand_dimsInsert a size-1 axis into an array at a chosen position (numpy expand_dims)
Signature
Inputs
aVector|Matrix|Tensorrequired— The array to expand. A new length-1 axis is inserted, raising the rank by one.
Outputs
resultMatrix|Tensor— The same data with an added size-1 axis at `axis`. Unit preserved.
Parameters
| Key | Type | Default | Notes |
|---|---|---|---|
axis | int | 0 | Position of the inserted size-1 axis. Valid range is [-(ndim+1), ndim], so appending at the end is allowed; negative counts from the end. |
Description
Expand Dims inserts a new size-1 axis into an array at position axis, raising its rank by one — the numpy expand_dims operation. It is a pure reindexing / metadata op: the flat data is unchanged (an insert_axis on the underlying N-D array), so the unit is preserved.
axis may be negative; the valid range is , so you can insert at the very front, in the middle, or append at the end. Typical use is promoting a length- Vector into a row (axis=0) or an column (axis=1) so it lines up with a matrix operation. This is the inverse of tensor_squeeze.
Mathematics
Examples
Vector to row
A length-3 Vector [1,2,3] with axis=0 becomes shape [1, 3] (a row matrix). The data buffer is untouched.
Vector to column
The same [1,2,3] with axis=1 (or axis=-1) becomes shape [3, 1] — a column, ready to broadcast against a matrix.
Applications
- Promoting a Vector to a row or column so it broadcasts correctly against a Matrix in tensor math.
- Adding a batch or channel axis before a stacking or concatenation stage.
- Aligning array ranks to satisfy a downstream node that expects a specific dimensionality.
- Preparing the inverse of a squeeze to restore a dropped axis.
Neat
The operation moves zero floats — it is a pure axis-insert on the N-D array, so the physical unit rides through unchanged.
Because the appended position `ndim` is allowed, you can add a trailing axis (numpy's `axis=-1`) without special-casing.
Known issues
An out-of-range `axis` outside [-(ndim+1), ndim] is an error surfaced from the tensor layer.