@stdlib/ndarray-base-prepend-singleton-dimensions
v0.3.1
Published
Prepend singleton dimensions.
Readme
prependSingletonDimensions
Prepend singleton dimensions.
Installation
npm install @stdlib/ndarray-base-prepend-singleton-dimensionsUsage
var prependSingletonDimensions = require( '@stdlib/ndarray-base-prepend-singleton-dimensions' );prependSingletonDimensions( x, n, writable )
Returns an ndarray with a specified number of prepended singleton dimensions (i.e., dimensions whose size is equal to 1).
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, false );
// returns <ndarray>[ [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ] ]The function accepts the following arguments:
- x: input ndarray.
- n: number of singleton dimensions to prepend.
- writable: boolean indicating whether a returned ndarray should be writable.
Examples
var uniform = require( '@stdlib/random-uniform' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var prependSingletonDimensions = require( '@stdlib/ndarray-base-prepend-singleton-dimensions' );
var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 );
console.log( ndarray2array( x ) );
var y = prependSingletonDimensions( x, 3, false );
console.log( ndarray2array( y ) );Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
