Return a view of an input ndarray in which a specified dimension is expanded over multiple dimensions.
var unflatten = require( '@stdlib/ndarray/base/unflatten' );Returns a view of an input ndarray in which a specified dimension 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 out = unflatten( x, 0, [ 2, 3 ], false );
// 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.
- writable: boolean indicating whether a returned ndarray should be writable.
- The
writableparameter only applies to ndarray constructors supporting read-only instances.
var uniform = require( '@stdlib/random/discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var unflatten = require( '@stdlib/ndarray/base/unflatten' );
var x = uniform( [ 12 ], -100, 100 );
console.log( ndarray2array( x ) );
var out = unflatten( x, 0, [ 3, 4 ], false );
console.log( ndarray2array( out ) );