Skip to content

Latest commit

 

History

History
130 lines (75 loc) · 3.5 KB

File metadata and controls

130 lines (75 loc) · 3.5 KB

toReversedDimension

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

Usage

var toReversedDimension = require( '@stdlib/ndarray/to-reversed-dimension' );

toReversedDimension( x[, options] )

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

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

var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] );
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]

var y = toReversedDimension( x );
// returns <ndarray>[ [ 2.0, 1.0 ], [ 4.0, 3.0 ] ]

The function accepts the following arguments:

  • x: input ndarray.
  • options: function options (optional).

The function supports the following options:

  • dim: index of dimension along which to reverse elements. 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. Default: -1.

Examples

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

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

var y = toReversedDimension( x );
console.log( ndarray2array( y ) );