Return a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements.
var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' );Returns a string by joining one-dimensional ndarray elements using a specified separator for each pair of consecutive elements.
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var xbuf = [ 1, 2, 3, 4 ];
var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
var prefix = scalar2ndarray( 'op: ', {
'dtype': 'generic'
});
var suffix = scalar2ndarray( '', {
'dtype': 'generic'
});
var sbuf = [ ' + ', ' - ', ' != ' ];
var separators = new ndarray( 'generic', sbuf, [ 3 ], [ 1 ], 0, 'row-major' );
var out = gjoinBetween( [ x, prefix, suffix, separators ] );
// returns 'op: 1 + 2 - 3 != 4'The function has the following parameters:
-
arrays: array-like object containing the following ndarrays:
- a one-dimensional input ndarray.
- a zero-dimensional ndarray containing a prefix string.
- a zero-dimensional ndarray containing a suffix string.
- a one-dimensional ndarray containing separator strings.
- If the input ndarray is empty, the function returns the prefix and suffix joined together.
- The
separatorsndarray is assumed to have at leastN-1elements (i.e., equal to the number of "gaps" between consecutive elements), whereNis the number of elements in the input ndarray. - If an array element is either
nullorundefined, the function serializes the element as an empty string.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var filled = require( '@stdlib/array/base/filled' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var gjoinBetween = require( '@stdlib/blas/ext/base/ndarray/gjoin-between' );
var xbuf = discreteUniform( 10, -100, 100, {
'dtype': 'generic'
});
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
console.log( ndarray2array( x ) );
var prefix = scalar2ndarray( '[ ', {
'dtype': 'generic'
});
var suffix = scalar2ndarray( ' ]', {
'dtype': 'generic'
});
var sbuf = filled( ' | ', xbuf.length - 1 );
var separators = new ndarray( 'generic', sbuf, [ sbuf.length ], [ 1 ], 0, 'row-major' );
var out = gjoinBetween( [ x, prefix, suffix, separators ] );
console.log( out );