@stdlib/ndarray-unshift
v0.1.1
Published
Return a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray.
Readme
unshift
Return a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray.
Installation
npm install @stdlib/ndarray-unshiftUsage
var unshift = require( '@stdlib/ndarray-unshift' );unshift( x, ...values )
Returns a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray.
var array = require( '@stdlib/ndarray-array' );
var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = unshift( x, -2.0, -1.0, 0.0 );
// returns <ndarray>[ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ]The function accepts the following arguments:
- x: input ndarray. Must be one-dimensional.
- ...values: scalar values to prepend.
unshift.assign( x, ...values, out )
Prepends provided scalar values to a one-dimensional input ndarray and assigns the result to a provided one-dimensional output ndarray.
var array = require( '@stdlib/ndarray-array' );
var zeros = require( '@stdlib/ndarray-zeros' );
var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );
var y = zeros( [ 7 ] );
var out = unshift.assign( x, -2.0, -1.0, 0.0, y );
// returns <ndarray>[ -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0 ]
var bool = ( out === y );
// returns trueThe function accepts the following arguments:
- x: input ndarray. Must be one-dimensional.
- ...values: scalar values to prepend.
- out: output ndarray. Must be one-dimensional.
Notes
Examples
var discreteUniform = require( '@stdlib/random-discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var unshift = require( '@stdlib/ndarray-unshift' );
var opts = {
'dtype': 'generic'
};
var x = discreteUniform( [ 6 ], 0, 10, opts );
console.log( ndarray2array( x ) );
var out = unshift( x, 12, 14 );
console.log( ndarray2array( out ) );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.
