@stdlib/array-base-take-indexed2
v0.1.1
Published
Take elements from two indexed arrays in a single pass.
Readme
takeIndexed2
Take elements from two indexed arrays in a single pass.
Installation
npm install @stdlib/array-base-take-indexed2Usage
var takeIndexed2 = require( '@stdlib/array-base-take-indexed2' );takeIndexed2( x, y, indices )
Takes elements from two indexed arrays in a single pass.
var x = [ 1, 2, 3, 4 ];
var y = [ 5, 6, 7, 8 ];
var out = takeIndexed2( x, y, [ 1, 3 ] );
// returns [ [ 2, 4 ], [ 6, 8 ] ]If indices is an empty array, the function returns empty arrays.
var x = [ 1, 2, 3, 4 ];
var y = [ 5, 6, 7, 8 ];
var out = takeIndexed2( x, y, [] );
// returns [ [], [] ]Notes
- The function does not perform bounds checking. If an index is less than zero or greater than the maximum index of
xory, the value of the corresponding element in the respective output array is undefined. - An indexed array-like object is a data structure in which one retrieves elements via integer indices using bracket
[]notation (e.g.,Float64Array,Int32Array,Array, etc). This is in contrast to an accessor array-like object in which one retrieves elements usinggetandsetmethods (e.g.,Complex64ArrayandComplex128Array).
Examples
var filledBy = require( '@stdlib/array-base-filled-by' );
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
var linspace = require( '@stdlib/array-base-linspace' );
var takeIndexed2 = require( '@stdlib/array-base-take-indexed2' );
// Generate linearly spaced arrays:
var x = linspace( 0, 100, 11 );
console.log( x );
var y = linspace( 100, 200, 11 );
console.log( y );
// Generate an array of random indices:
var N = discreteUniform( 5, 15 );
var indices = filledBy( N, discreteUniform.factory( 0, x.length-1 ) );
console.log( indices );
// Take a random sample of elements from `x` and `y`:
var out = takeIndexed2( x, y, indices );
console.log( out );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-2026. The Stdlib Authors.
