NumPy at least 3d inserts singleton axes according to the input dimensionality

A minimum of three dimensions does not identify one universal output shape. NumPy at least 3d follows different insertion rules for scalars, vectors and matrices. Academia Master Trader presents this English lesson for readers in Togo, using constructed inputs to explain those rules without confusing new axes with new numerical data.

A vector gains axes before and after its entries

After import numpy as np, define x = np.array([4,7,10]). Its shape is (3,). The call np.atleast_3d(x) returns an array with shape (1,3,1).

The original length-three axis becomes the middle axis. A singleton axis appears before it and another singleton axis appears after it. The result still contains three numerical entries.

This convention is more specific than simply adding dimensions somewhere. Shapes (1,1,3) and (3,1,1) also have three axes, but they are not the shape produced for this vector by this helper.

When a later expression assigns meaning to axis positions, write down the resulting shape before combining the data with other arrays.

NumPy at least 3d shape rules

A matrix gains one final singleton axis

For matrix = np.array([[1,2,3],[4,5,6]]), the input shape is (2,3). The call np.atleast_3d(matrix) produces shape (2,3,1).

The two existing axes keep their order and lengths. One new length-one axis follows them. This is not a transposition and does not combine the two original axes.

The six original entries remain present. Adding a final singleton direction does not repeat those six entries across several layers.

For a scalar, np.atleast_3d(9) produces shape (1,1,1). Its single value occupies an array with three singleton axes.

Existing higher-dimensional shapes are preserved

An input that already has three dimensions keeps its shape. For already = np.zeros((2,3,4)), the call np.atleast_3d(already) still has shape (2,3,4).

The same minimum rule permits more than three dimensions. For an input with shape (2,3,4,5), the output retains all four axes rather than collapsing them to three.

The helper therefore establishes a lower bound on dimensionality, not a fixed layout suitable for every later operation. A downstream function may impose additional requirements on axis order or axis lengths.

Multiple inputs remain separate arrays

The call a,b = np.atleast_3d([4,7,10],[[1,2],[3,4]]) returns separate arrays with shapes (1,3,1) and (2,2,1). It does not join those inputs into one object or make their shapes identical.

Non-array inputs are converted to arrays. Copies are avoided where possible, so an output view can share data with an existing source array.

If later edits need independent storage, take an explicit copy after applying the dimensionality rule. Shape conversion and ownership of editable values are separate decisions.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the input dimensionality, inserted singleton axes and final shape before relying on the result.