Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

toReversedDimensions

Return a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed.

Usage

var toReversedDimensions = require( '@stdlib/ndarray/to-reversed-dimensions' );

toReversedDimensions( x, dims )

Returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed.

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 = toReversedDimensions( x, [ 0, 1 ] );
// returns <ndarray>[ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ]

The function accepts the following arguments:

  • x: input ndarray.
  • dims: indices of dimensions along which to reverse elements. If a dimension index is provided as an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value -1.

Examples

var uniform = require( '@stdlib/random/discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var toReversedDimensions = require( '@stdlib/ndarray/to-reversed-dimensions' );

var x = uniform( [ 3, 3, 3 ], -100, 100 );
console.log( ndarray2array( x ) );

var y = toReversedDimensions( x, [ 0, 2 ] );
console.log( ndarray2array( y ) );