@stdlib/array-base-cartesian-power
v0.2.2
Published
Return the Cartesian power.
Downloads
12
Readme
cartesianPower
Return the Cartesian power.
Installation
npm install @stdlib/array-base-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 ] ]
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.