Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

prependSingletonDimensions

Return a read-only view of an input ndarray with a specified number of prepended singleton dimensions.

Usage

var prependSingletonDimensions = require( '@stdlib/ndarray/prepend-singleton-dimensions' );

prependSingletonDimensions( x, n )

Returns a read-only view of an input ndarray with a specified number of prepended singleton dimensions.

var array = require( '@stdlib/ndarray/array' );

// Create a 2x2 ndarray:
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]

// Prepend singleton dimensions:
var y = prependSingletonDimensions( x, 3 );
// returns <ndarray>[ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ]

The function accepts the following arguments:

  • x: input ndarray.
  • n: number of singleton dimensions to prepend.

Examples

var uniform = require( '@stdlib/random/uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var prependSingletonDimensions = require( '@stdlib/ndarray/prepend-singleton-dimensions' );

var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 );
console.log( ndarray2array( x ) );

var y = prependSingletonDimensions( x, 3 );
console.log( ndarray2array( y ) );