Skip to content

Latest commit

 

History

History
155 lines (95 loc) · 4.02 KB

File metadata and controls

155 lines (95 loc) · 4.02 KB

push

Return a one-dimensional ndarray formed by appending the provided scalar values to the input ndarray.

Usage

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

push( x, ...values )

Returns a one-dimensional ndarray formed by appending the provided scalar values to the input ndarray.

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

var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );

var out = push( x, 5.0, 6.0, 7.0 );
// returns <ndarray>

var arr = ndarray2array( out );
// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]

The function accepts the following arguments:

  • arr: input ndarray.
  • ...values: scalar values to append.

push.assign( x, ...values, out )

Appends the provided scalar values to the 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 ndarray2array = require( '@stdlib/ndarray/to-array' );

var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );
var y = zeros( [ 7 ] );

var out = push.assign( x, 5.0, 6.0, 7.0, y );
// returns <ndarray>

var bool = ( out === y );
// returns true

var arr = ndarray2array( y );
// returns [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]

The function accepts the following arguments:

  • arr: input ndarray.
  • out: output ndarray.
  • ...values: scalar values to append.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var array = require( '@stdlib/ndarray/array' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var push = require( '@stdlib/ndarray/push' );

var opts = {
    'dtype': 'generic'
};
var x = array( discreteUniform( 6, 0, 10, opts ), opts );
console.log( ndarray2array( x ) );

var out = push( x, 12.0, 14.0 );
console.log( ndarray2array( out ) );