Remove singleton dimensions.
var removeSingletonDimensions = require( '@stdlib/ndarray/base/remove-singleton-dimensions' );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.
- The
writableparameter 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.
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 ) );