Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

unflatten

Return a read-only view of an input ndarray in which a specified dimension is expanded over multiple dimensions.

Usage

var unflatten = require( '@stdlib/ndarray/unflatten' );

unflatten( x, dim, sizes )

Returns a read-only view of an input ndarray in which a specified dimension is expanded over multiple dimensions.

var array = require( '@stdlib/ndarray/array' );

// Create a 1-dimensional ndarray:
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 ]

// Unflatten the first dimension:
var y = unflatten( 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.

Examples

var uniform = require( '@stdlib/random/uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var unflatten = require( '@stdlib/ndarray/unflatten' );

var x = uniform( [ 12 ], -10.0, 10.0 );
console.log( ndarray2array( x ) );

var y = unflatten( x, 0, [ 3, 4 ] );
console.log( ndarray2array( y ) );