Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

rotl90

Return a read-only view of a matrix (or a stack of matrices) rotated 90 degrees counterclockwise.

Usage

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

rotl90( x, k )

Returns a read-only view of a matrix (or a stack of matrices) rotated 90 degrees counterclockwise.

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

The function accepts the following arguments:

  • x: input ndarray.
  • k: number of times to rotate by 90 degrees. Positive values rotate counterclockwise. Negative values rotate clockwise.

Notes

  • If k > 0, the function rotates the matrix counterclockwise.
  • If k < 0, the function rotates the matrix clockwise.
  • If provided an ndarray with fewer than two dimensions, the function does not perform a rotation and simply returns a new view of the input ndarray.

Examples

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

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

var y = rotl90( x, 1 );
console.log( ndarray2array( y ) );