cartesianPower

Return the Cartesian power.

Usage

var cartesianPower = require( '@stdlib/array/base/cartesian-power' );

cartesianPower( x, n )

Returns the Cartesian power.

var x = [ 1, 2 ];

var out = cartesianPower( x, 2 );
// returns [ [ 1, 1 ], [ 1, 2 ], [ 2, 1 ], [ 2, 2 ] ]

If provided an empty array, the function returns an empty array.

var out = cartesianPower( [], 2 );
// returns []

If n is less than or equal to zero, the function returns an empty array.

var out = cartesianPower( [ 1, 2 ], 0 );
// returns []

Examples

var linspace = require( '@stdlib/array/base/linspace' );
var cartesianPower = require( '@stdlib/array/base/cartesian-power' );

var x = linspace( 0, 5, 6 );

var out = cartesianPower( x, 3 );
// returns [ [ 0, 0, 0 ], [ 0, 0, 1 ], ..., [ 5, 5, 4 ], [ 5, 5, 5 ] ]
Did you find this page helpful?