Return a new ndarray in which a specified dimension of an input ndarray is expanded over multiple dimensions.
var toUnflattened = require( '@stdlib/ndarray/base/to-unflattened' );Returns a new ndarray in which a specified dimension of an input ndarray is expanded over multiple dimensions.
var array = require( '@stdlib/ndarray/array' );
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
// returns <ndarray>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
var y = toUnflattened( x, 0, [ 2, 3 ] );
// returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]The function accepts the following arguments:
- x: input ndarray.
- dim: dimension to be unflattened. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value
-1. - sizes: new shape of the unflattened dimension.
var uniform = require( '@stdlib/random/discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var toUnflattened = require( '@stdlib/ndarray/base/to-unflattened' );
var x = uniform( [ 12 ], -100, 100 );
console.log( ndarray2array( x ) );
var y = toUnflattened( x, 0, [ 3, 4 ] );
console.log( ndarray2array( y ) );