Return a read-only view of an input
ndarrayin which the order of elements along a specified dimension is reversed.
var reverseDimension = require( '@stdlib/ndarray/reverse-dimension' );Returns a read-only view of an input ndarray in which the order of elements along a specified dimension is reversed.
var array = require( '@stdlib/ndarray/array' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], {
'shape': [ 3, 2 ]
});
// returns <ndarray>
var arr = ndarray2array( x );
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
var y = reverseDimension( x, 0 );
// returns <ndarray>
arr = ndarray2array( y );
// returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]The function accepts the following arguments:
- x: input ndarray.
- 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.
var uniform = require( '@stdlib/random/uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var reverseDimension = require( '@stdlib/ndarray/reverse-dimension' );
var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 );
console.log( ndarray2array( x ) );
var y = reverseDimension( x, 0 );
console.log( ndarray2array( y ) );