Skip to content

Latest commit

 

History

History
138 lines (82 loc) · 3.51 KB

File metadata and controls

138 lines (82 loc) · 3.51 KB

unflattenShape

Expand a dimension over multiple dimensions.

Usage

var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' );

unflattenShape( shape, dim, sizes )

Expands a dimension over multiple dimensions.

var sh = unflattenShape( [ 6, 2, 1 ], 0, [ 3, 2 ] );
// returns [ 3, 2, 2, 1 ]

The function accepts the following parameters:

  • shape: array shape.
  • 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.

unflattenShape.assign( shape, dim, sizes, out )

Expands a dimension over multiple dimensions and assigns results to a provided output array.

var o = [ 0, 0, 0, 0 ];

var out = unflattenShape.assign( [ 6, 2, 1 ], 0, [ 3, 2 ], o );
// returns [ 3, 2, 2, 1 ]

var bool = ( out === o );
// returns true

The function accepts the following parameters:

  • shape: array shape.
  • 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.
  • out: output array.

Examples

var unflattenShape = require( '@stdlib/ndarray/base/unflatten-shape' );

var out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 2 ] );
// returns [ 2, 2, 2, 1 ]

out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 1, 2 ] );
// returns [ 2, 2, 1, 2, 1 ]

out = unflattenShape( [ 2, 4, 1 ], 1, [ 2, 1, 1, 2 ] );
// returns [ 2, 2, 1, 1, 2, 1 ]