Return a read-only view of an input ndarray rotated
90degrees in a specified plane.
var rot90 = require( '@stdlib/ndarray/rot90' );Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane.
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 = rot90( x );
// returns <ndarray>[ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ]The function accepts the following arguments:
- x: input
ndarray. - options: function options.
The function accepts the following options:
- k: number of times to rotate by
90degrees. Positive values rotate counterclockwise. Negative values rotate clockwise. Default:1. - dims: dimension indices defining the plane of rotation. Must contain exactly two unique dimension indices. 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. Default:[-2, -1].
- If
options.k > 0, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray andoptions.dims = [0, 1], the function rotates the plane counterclockwise. - If
options.k < 0, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray andoptions.dims = [0, 1], the function rotates the plane clockwise. - Each provided dimension index must reside on the interval
[-ndims, ndims-1].
var uniform = require( '@stdlib/random/uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var rot90 = require( '@stdlib/ndarray/rot90' );
var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 );
console.log( ndarray2array( x ) );
var y = rot90( x );
console.log( ndarray2array( y ) );