Concatenate a list of ndarrays along the last dimension.
var hconcat = require( '@stdlib/ndarray/hconcat' );Concatenates a list of ndarrays along the last dimension.
var array = require( '@stdlib/ndarray/array' );
var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] );
// returns <ndarray>[ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ]
var out = hconcat( [ x, y ] );
// returns <ndarray>[ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ]The function accepts the following arguments:
- arrays: a list of input ndarrays. The data type of the output ndarray is determined by applying type promotion rules to the list of input ndarrays. If provided ndarrays having different memory layouts, the output ndarray has the default order.
Concatenates a list of ndarrays along the last dimension and assigns results to a provided 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 ] ] );
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
var y = array( [ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ] );
// returns <ndarray>[ [ 5.0, 6.0, 7.0 ], [ 8.0, 9.0, 10.0 ] ]
var z = zeros( [ 2, 5 ] );
// returns <ndarray>[ [ 0.0, 0.0, 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ]
var out = hconcat.assign( [ x, y ], z );
// returns <ndarray>[ [ 1.0, 2.0, 5.0, 6.0, 7.0 ], [ 3.0, 4.0, 8.0, 9.0, 10.0 ] ]
var bool = ( out === z );
// returns trueThe function accepts the following arguments:
var discreteUniform = require( '@stdlib/random/discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var hconcat = require( '@stdlib/ndarray/hconcat' );
var x = discreteUniform( [ 2, 2 ], 0, 10, {
'dtype': 'generic'
});
console.log( ndarray2array( x ) );
var y = discreteUniform( [ 2, 3 ], 0, 10, {
'dtype': 'generic'
});
console.log( ndarray2array( y ) );
var out = hconcat( [ x, y ] );
console.log( ndarray2array( out ) );