input array
axis at which to insert a singleton dimension
output array
var array = require( `@stdlib/ndarray/array` );
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>
var shx = x.shape;
// returns [ 2, 2 ]
var y = expandDimensions( x, 1 );
// returns <ndarray>
var shy = y.shape;
// returns [ 2, 1, 2 ]
var v = y.get( 0, 0, 0 );
// returns 1
v = y.get( 0, 0, 1 );
// returns 2
v = y.get( 1, 0, 0 );
// returns 3
v = y.get( 1, 0, 1 );
// returns 4
Expands the shape of an array by inserting a new dimension of size one at a specified axis.
Notes
[-N-1, N]
, whereN
is the rank (i.e., number of dimensions) of the provided input array. If provided a negativeaxis
, the axis position at which to insert a singleton dimension is computed asN + axis + 1
. Hence, if provided-1
, the resolved axis position isN
(i.e., a singleton dimension is appended to the input array).