base
Base (i.e., lower-level) array utilities.
Usage
var ns = require( '@stdlib/array/base' );
ns
Array utilities.
var o = ns;
// returns {...}
The namespace exports the following:
accessorGetter( dtype )
: return an accessor function for retrieving an element from an array-like object supporting the get/set protocol.accessorSetter( dtype )
: return an accessor function for setting an element in an array-like object supporting the get/set protocol.AccessorArray( arr )
: create a minimal array-like object supporting the accessor protocol from another array-like object.accessors( x )
: return element accessors for a provided array-like object.anyByRight( x, predicate[, thisArg] )
: test whether at least one element in an array passes a test implemented by a predicate function, while iterating from right to left.anyBy( x, predicate[, thisArg] )
: test whether at least one element in an array passes a test implemented by a predicate function.any( x )
: test whether at least one element in an array is truthy.arraylike2object( x )
: convert an array-like object to an object likely to have the same "shape".assert
: base array assertion utilities.at( x, index )
: return an element from an array.at2d( x, i0, i1 )
: return an element from a two-dimensional nested array.at3d( x, i0, i1, i2 )
: return an element from a three-dimensional nested array.at4d( x, i0, i1, i2, i3 )
: return an element from a four-dimensional nested array.at5d( x, i0, i1, i2, i3, i4 )
: return an element from a five-dimensional nested array.atnd( x, i0[, ...indices] )
: return an element from an n-dimensional nested array.bifurcateEntriesBy( x, predicate[, thisArg] )
: split element entries into two groups according to a predicate function.bifurcateEntries( x, filter )
: split array element entries into two groups.bifurcateIndicesBy( x, predicate[, thisArg] )
: split element indices into two groups according to a predicate function.bifurcateIndices( x, filter )
: split array element indices into two groups.bifurcateValuesBy( x, predicate[, thisArg] )
: split element values into two groups according to a predicate function.bifurcateValues( x, filter )
: split array element values into two groups.binary2d( arrays, shape, fcn )
: apply a binary callback to elements in two two-dimensional nested input arrays and assign results to elements in a two-dimensional nested output array.binary3d( arrays, shape, fcn )
: apply a binary callback to elements in two three-dimensional nested input arrays and assign results to elements in a three-dimensional nested output array.binary4d( arrays, shape, fcn )
: apply a binary callback to elements in two four-dimensional nested input arrays and assign results to elements in a four-dimensional nested output array.binary5d( arrays, shape, fcn )
: apply a binary callback to elements in two five-dimensional nested input arrays and assign results to elements in a five-dimensional nested output array.binarynd( arrays, shape, fcn )
: apply a binary callback to elements in two n-dimensional nested input arrays and assign results to elements in an n-dimensional nested output array.broadcastArray( x, inShape, outShape )
: broadcast an array to a specified shape.bbinary2d( arrays, shapes, fcn )
: apply a binary callback to elements in two broadcasted nested input arrays and assign results to elements in a two-dimensional nested output array.bbinary3d( arrays, shapes, fcn )
: apply a binary callback to elements in two broadcasted nested input arrays and assign results to elements in a three-dimensional nested output array.bbinary4d( arrays, shapes, fcn )
: apply a binary callback to elements in two broadcasted nested input arrays and assign results to elements in a four-dimensional nested output array.bbinary5d( arrays, shapes, fcn )
: apply a binary callback to elements in two broadcasted nested input arrays and assign results to elements in a five-dimensional nested output array.bquaternary2d( arrays, shapes, fcn )
: apply a quaternary callback to elements in four broadcasted nested input arrays and assign results to elements in a two-dimensional nested output array.bquinary2d( arrays, shapes, fcn )
: apply a quinary callback to elements in four broadcasted nested input arrays and assign results to elements in a two-dimensional nested output array.bternary2d( arrays, shapes, fcn )
: apply a ternary callback to elements in three broadcasted nested input arrays and assign results to elements in a two-dimensional nested output array.bunary2d( arrays, shapes, fcn )
: apply a unary callback to elements in a broadcasted nested input array and assign results to elements in a two-dimensional nested output array.bunary3d( arrays, shapes, fcn )
: apply a unary callback to elements in a broadcasted nested input array and assign results to elements in a three-dimensional nested output array.bunary4d( arrays, shapes, fcn )
: apply a unary callback to elements in a broadcasted nested input array and assign results to elements in a four-dimensional nested output array.bunary5d( arrays, shapes, fcn )
: apply a unary callback to elements in a broadcasted nested input array and assign results to elements in a five-dimensional nested output array.cartesianPower( x, n )
: return the Cartesian power.cartesianProduct( x1, x2 )
: return the Cartesian product.cartesianSquare( x )
: return the Cartesian square.copyIndexed( x )
: copy the elements of an indexed array-like object to a new "generic" array.copy( x )
: copy the elements of an array-like object to a new "generic" array.countFalsy( x )
: count the number of falsy elements in an array.countIf( x, predicate[, thisArg] )
: count the number of elements in an array which pass a test implemented by a predicate function.countSameValueZero( x, value )
: count the number of elements in an array that are equal to a specified value.countSameValue( x, value )
: count the number of elements in an array that are equal to a specified value.countTruthy( x )
: count the number of truthy elements in an array.cuany( x )
: cumulatively test whether at least one element in a provided array is truthy.cuevery( x )
: cumulatively test whether every element in a provided array is truthy.cunone( x )
: cumulatively test whether every element in a provided array is falsy.dedupe( x, limit, equalNaNs )
: remove consecutive duplicated values.everyByRight( x, predicate[, thisArg] )
: test whether all elements in an array pass a test implemented by a predicate function, iterating from right to left.everyBy( x, predicate[, thisArg] )
: test whether all elements in an array pass a test implemented by a predicate function.every( x )
: test whether all elements in an array are truthy.fancySliceAssign( x, y, s, strict )
: assign element values from a broadcasted input array to corresponding elements in an output array.fancySlice( x, s, strict )
: return a shallow copy of a portion of an array.filledBy( len, clbk[, thisArg] )
: create a filled "generic" array according to a provided callback function.filled( value, len )
: create a filled "generic" array.filled2dBy( shape, clbk[, thisArg] )
: create a filled two-dimensional nested array according to a provided callback function.filled2d( value, shape )
: create a filled two-dimensional nested array.filled3dBy( shape, clbk[, thisArg] )
: create a filled three-dimensional nested array according to a provided callback function.filled3d( value, shape )
: create a filled three-dimensional nested array.filled4dBy( shape, clbk[, thisArg] )
: create a filled four-dimensional nested array according to a provided callback function.filled4d( value, shape )
: create a filled four-dimensional nested array.filled5dBy( shape, clbk[, thisArg] )
: create a filled five-dimensional nested array according to a provided callback function.filled5d( value, shape )
: create a filled five-dimensional nested array.filledndBy( shape, clbk[, thisArg] )
: create a filled n-dimensional nested array according to a provided callback function.fillednd( value, shape )
: create a filled n-dimensional nested array.filter( x, predicate[, thisArg] )
: return a shallow copy of an array containing only those elements which pass a test implemented by a predicate function.first( x )
: return the first element of an array-like object.flattenBy( x, shape, colexicographic, clbk[, thisArg] )
: flatten an n-dimensional nested array according to a callback function.flatten( x, shape, colexicographic )
: flatten an n-dimensional nested array.flatten2dBy( x, shape, colexicographic, clbk[, thisArg] )
: flatten a two-dimensional nested array according to a callback function.flatten2d( x, shape, colexicographic )
: flatten a two-dimensional nested array.flatten3dBy( x, shape, colexicographic, clbk[, thisArg] )
: flatten a three-dimensional nested array according to a callback function.flatten3d( x, shape, colexicographic )
: flatten a three-dimensional nested array.flatten4dBy( x, shape, colexicographic, clbk[, thisArg] )
: flatten a four-dimensional nested array according to a callback function.flatten4d( x, shape, colexicographic )
: flatten a four-dimensional nested array.flatten5dBy( x, shape, colexicographic, clbk[, thisArg] )
: flatten a five-dimensional nested array according to a callback function.flatten5d( x, shape, colexicographic )
: flatten a five-dimensional nested array.fliplr2d( x )
: reverse the order of elements along the last dimension of a two-dimensional nested input array.fliplr3d( x )
: reverse the order of elements along the last dimension of a three-dimensional nested input array.fliplr4d( x )
: reverse the order of elements along the last dimension of a four-dimensional nested input array.fliplr5d( x )
: reverse the order of elements along the last dimension of a five-dimensional nested input array.flipud2d( x )
: reverse the order of elements along the first dimension of a two-dimensional nested input array.flipud3d( x )
: reverse the order of elements along the second-to-last dimension of a three-dimensional nested input array.flipud4d( x )
: reverse the order of elements along the second-to-last dimension of a four-dimensional nested input array.flipud5d( x )
: reverse the order of elements along the second-to-last dimension of a five-dimensional nested input array.strided2array( N, x, stride, offset )
: convert a strided array to a non-strided generic array.getter( dtype )
: return an accessor function for retrieving an element from an indexed array-like object.groupEntriesBy( x, indicator[, thisArg] )
: group element entries according to an indicator function.groupEntries( x, groups )
: group element entries as arrays associated with distinct keys.groupIndicesBy( x, indicator[, thisArg] )
: group element indices according to an indicator function.groupIndices( x, groups )
: group element indices as arrays associated with distinct keys.groupValuesBy( x, indicator[, thisArg] )
: group element values according to an indicator function.groupValues( x, groups )
: group elements as arrays associated with distinct keys.incrspace( start, stop, increment )
: generate a linearly spaced numeric array according to a provided increment.indexOf( x, searchElement, fromIndex, equalNaNs )
: return the index of the first element which equals a provided search element.join( x, separator )
: return a string created by joining array elements using a specified separator.lastIndexOf( x, searchElement, fromIndex, equalNaNs )
: return the index of the last element which equals a provided search element.last( x )
: return the last element of an array-like object.linspace( start, stop, length )
: generate a linearly spaced numeric array.logspace( a, b, length )
: generate a logarithmically spaced numeric array.map2d( x, shape, fcn[, thisArg] )
: apply a function to elements in a two-dimensional nested input array and assign results to elements in a new two-dimensional nested output array.map3d( x, shape, fcn[, thisArg] )
: apply a function to elements in a three-dimensional nested input array and assign results to elements in a new three-dimensional nested output array.map4d( x, shape, fcn[, thisArg] )
: apply a function to elements in a four-dimensional nested input array and assign results to elements in a new four-dimensional nested output array.map5d( x, shape, fcn[, thisArg] )
: apply a function to elements in a five-dimensional nested input array and assign results to elements in a new five-dimensional nested output array.minSignedIntegerDataType( value )
: determine the minimum array data type for storing a provided signed integer value.minUnsignedIntegerDataType( value )
: determine the minimum array data type for storing a provided unsigned integer value.mskbinary2d( arrays, shape, fcn )
: apply a binary callback to elements in two two-dimensional nested input arrays according to elements in a two-dimensional nested mask array and assign results to elements in a two-dimensional nested output array.mskfilter( x, mask )
: apply a mask to a provided input array.mskput( x, mask, values, mode )
: replace elements of an array with provided values according to a provided mask array.mskreject( x, mask )
: apply a mask to a provided input array.mskunary2d( arrays, shape, fcn )
: apply a unary callback to elements in a two-dimensional nested input array according to elements in a two-dimensional nested mask array and assign results to elements in a two-dimensional nested output array.mskunary3d( arrays, shape, fcn )
: apply a unary callback to elements in a three-dimensional nested input array according to elements in a three-dimensional nested mask array and assign results to elements in a three-dimensional nested output array.nCartesianProduct( x1, x2[, ...xN] )
: return the n-fold Cartesian product.noneByRight( x, predicate[, thisArg] )
: test whether all elements in an array fail a test implemented by a predicate function, iterating from right to left.noneBy( x, predicate[, thisArg] )
: test whether all elements in an array fail a test implemented by a predicate function.none( x )
: test whether all elements in an array are falsy.oneTo( n )
: generate a linearly spaced numeric array whose elements increment by 1 starting from one.ones( len )
: create a "generic" array filled with ones.ones2d( shape )
: create a two-dimensional nested array filled with ones.ones3d( shape )
: create a three-dimensional nested array filled with ones.ones4d( shape )
: create a four-dimensional nested array filled with ones.ones5d( shape )
: create a five-dimensional nested array filled with ones.onesnd( shape )
: create an n-dimensional nested array filled with ones.place( x, mask, values, mode )
: replace elements of an array with provided values according to a provided mask array.put( x, indices, values, mode )
: replace specified elements of an array with provided values.quaternary2d( arrays, shape, fcn )
: apply a quaternary callback to elements in four two-dimensional nested input arrays and assign results to elements in a two-dimensional nested output array.quaternary3d( arrays, shape, fcn )
: apply a quaternary callback to elements in four three-dimensional nested input arrays and assign results to elements in a three-dimensional nested output array.quaternary4d( arrays, shape, fcn )
: apply a quaternary callback to elements in four four-dimensional nested input arrays and assign results to elements in a four-dimensional nested output array.quaternary5d( arrays, shape, fcn )
: apply a quaternary callback to elements in four five-dimensional nested input arrays and assign results to elements in a five-dimensional nested output array.quinary2d( arrays, shape, fcn )
: apply a quinary callback to elements in five two-dimensional nested input arrays and assign results to elements in a two-dimensional nested output array.quinary3d( arrays, shape, fcn )
: apply a quinary callback to elements in five three-dimensional nested input arrays and assign results to elements in a three-dimensional nested output array.quinary4d( arrays, shape, fcn )
: apply a quinary callback to elements in five four-dimensional nested input arrays and assign results to elements in a four-dimensional nested output array.quinary5d( arrays, shape, fcn )
: apply a quinary callback to elements in five five-dimensional nested input arrays and assign results to elements in a five-dimensional nested output array.reject( x, predicate[, thisArg] )
: return a shallow copy of an array containing only those elements which fail a test implemented by a predicate function.removeAt( x, index )
: remove an element from an array.resolveGetter( x )
: return an accessor function for retrieving an element from an array-like object.resolveSetter( x )
: return an accessor function for setting an element in an array-like object.reverse( x )
: reverse an array in-place.setter( dtype )
: return an accessor function for setting an element in an indexed array-like object.slice( x, start, end )
: return a shallow copy of a portion of an array.strided2array2d( x, shape, strides, offset )
: convert a strided array to a two-dimensional nested array.strided2array3d( x, shape, strides, offset )
: convert a strided array to a three-dimensional nested array.strided2array4d( x, shape, strides, offset )
: convert a strided array to a four-dimensional nested array.strided2array5d( x, shape, strides, offset )
: convert a strided array to a five-dimensional nested array.takeIndexed( x, indices )
: take elements from an indexed array.take( x, indices, mode )
: take elements from an array.take2d( x, indices, dimension, mode )
: take elements from a two-dimensional nested array.take3d( x, indices, dimension, mode )
: take elements from a three-dimensional nested array.ternary2d( arrays, shape, fcn )
: apply a ternary callback to elements in three two-dimensional nested input arrays and assign results to elements in a two-dimensional nested output array.ternary3d( arrays, shape, fcn )
: apply a ternary callback to elements in three three-dimensional nested input arrays and assign results to elements in a three-dimensional nested output array.ternary4d( arrays, shape, fcn )
: apply a ternary callback to elements in three four-dimensional nested input arrays and assign results to elements in a four-dimensional nested output array.ternary5d( arrays, shape, fcn )
: apply a ternary callback to elements in three five-dimensional nested input arrays and assign results to elements in a five-dimensional nested output array.toAccessorArray( arr )
: convert an array-like object to a minimal array-like object supporting the accessor protocol.toDeduped( x, limit, equalNaNs )
: copy elements to a new "generic" array after removing consecutive duplicated values.toReversed( x )
: return a new array with elements in reverse order.unary2dBy( arrays, shape, fcn, clbk[, thisArg] )
: apply a unary function to each element retrieved from a two-dimensional nested input array according to a callback function and assign results to elements in a two-dimensional nested output array.unary2d( arrays, shape, fcn )
: apply a unary callback to elements in a two-dimensional nested input array and assign results to elements in a two-dimensional nested output array.unary3d( arrays, shape, fcn )
: apply a unary callback to elements in a three-dimensional nested input array and assign results to elements in a three-dimensional nested output array.unary4d( arrays, shape, fcn )
: apply a unary callback to elements in a four-dimensional nested input array and assign results to elements in a four-dimensional nested output array.unary5d( arrays, shape, fcn )
: apply a unary callback to elements in a five-dimensional nested input array and assign results to elements in a five-dimensional nested output array.unarynd( arrays, shape, fcn )
: apply a unary callback to elements in an n-dimensional nested input array and assign results to elements in an n-dimensional nested output array.unitspace( start, stop )
: generate a linearly spaced numeric array whose elements increment by 1.where( condition, x, y )
: take elements from either one of two arrays depending on a condition.arrayWith( x, index, value )
: return a new array with the element at the specified index replaced with a provided value.without( x, index )
: return a new array containing every element from an input array, except for the element at a specified index.zeroTo( n )
: generate a linearly spaced numeric array whose elements increment by 1 starting from zero.zeros( len )
: create a zero-filled "generic" array.zeros2d( shape )
: create a zero-filled two-dimensional nested array.zeros3d( shape )
: create a zero-filled three-dimensional nested array.zeros4d( shape )
: create a zero-filled four-dimensional nested array.zeros5d( shape )
: create a zero-filled five-dimensional nested array.zerosnd( shape )
: create a zero-filled n-dimensional nested array.
Examples
var randu = require( '@stdlib/random/base/randu' );
var ns = require( '@stdlib/array/base' );
// Create a zero-filled array:
var zeros = ns.zeros( 5 );
// returns [ 0, 0, 0, 0, 0 ]
// Create an array filled with a specific value:
var filled = ns.filled( 7, 4 );
// returns [ 7, 7, 7, 7 ]
// Create a linearly spaced array:
var linear = ns.linspace( 0, 1, 5 );
// returns [ 0, 0.25, 0.5, 0.75, 1 ]
// Create a two-dimensional array:
var arr2d = ns.ones2d( [ 2, 3 ] );
// returns [ [ 1, 1, 1 ], [ 1, 1, 1 ] ]
// Map a function over a 2D array:
var squared = ns.map2d( arr2d, [ 2, 3 ], randu );
// e.g., returns [ [ ~0.123, ~0.789, ~0.456 ], [ ~0.321, ~0.654, ~0.987 ] ]