Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

transpose

Return a read-only view of an input ndarray in which the last two dimensions are transposed.

Usage

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

transpose( x )

Returns a read-only view of an input ndarray in which the last two dimensions are transposed.

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

The function accepts the following arguments:

Notes

  • The function operates on a stack of matrices, transposing the last two dimensions of the input ndarray.
  • The input ndarray must have two or more dimensions.

Examples

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

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

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