Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "ndarray/base/expand-dimensions/docs/types/index.d"

Index

Functions

Functions

Export assignment expandDimensions

  • Expands the shape of an array by inserting a new dimension of size one at a specified axis.

    Notes

    • A provided axis must reside on the interval [-N-1, N], where N is the rank (i.e., number of dimensions) of the provided input array. If provided a negative axis, the axis position at which to insert a singleton dimension is computed as N + axis + 1. Hence, if provided -1, the resolved axis position is N (i.e., a singleton dimension is appended to the input array).

    Parameters

    • x: ndarray

      input array

    • axis: number

      axis at which to insert a singleton dimension

    Returns ndarray

    output array

    Example

    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