cartesianSquare

Return the Cartesian square.

Usage

var cartesianSquare = require( '@stdlib/array/base/cartesian-square' );

cartesianSquare( x )

Returns the Cartesian square.

var x = [ 1, 2 ];

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

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

var out = cartesianSquare( [] );
// returns []

Examples

var linspace = require( '@stdlib/array/base/linspace' );
var cartesianSquare = require( '@stdlib/array/base/cartesian-square' );

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

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