broadcasted array
var array = require( `@stdlib/ndarray/array` );
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>
var shx = x.shape;
// returns [ 2, 2 ]
var y = maybeBroadcastArray( x, [ 3, 2, 2 ] );
// returns <ndarray>
var shy = y.shape;
// returns [ 3, 2, 2 ]
var v = y.get( 0, 0, 0 );
// returns 1
v = y.get( 0, 0, 1 );
// returns 2
v = y.get( 1, 0, 0 );
// returns 1
v = y.get( 1, 1, 0 );
// returns 3
v = y.get( 2, 0, 0 );
// returns 1
v = y.get( 2, 1, 1 );
// returns 4
Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.
Notes
input array cannot have more dimensions than the desired shape
input array dimension sizes must be
1
or equal to the corresponding dimension in the provided shapeinput array and desired shape must be broadcast compatible