Skip to content

Latest commit

 

History

History
127 lines (75 loc) · 3.24 KB

File metadata and controls

127 lines (75 loc) · 3.24 KB

removeSingletonDimensions

Remove singleton dimensions.

Usage

var removeSingletonDimensions = require( '@stdlib/ndarray/base/remove-singleton-dimensions' );

removeSingletonDimensions( x, writable )

Returns an ndarray without singleton dimensions (i.e., dimensions whose size is equal to 1).

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

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

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

The function accepts the following arguments:

  • x: input ndarray.
  • writable: boolean indicating whether a returned ndarray should be writable.

Notes

  • The writable parameter only applies to ndarray constructors supporting read-only instances.
  • The function always returns a new ndarray instance even if the input ndarray does not contain any singleton dimensions.

Examples

var uniform = require( '@stdlib/random/uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var removeSingletonDimensions = require( '@stdlib/ndarray/base/remove-singleton-dimensions' );

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

var y = removeSingletonDimensions( x, false );
console.log( ndarray2array( y ) );