@stdlib/array
v0.3.3
Published
Arrays.
Downloads
84,393
Readme
Arrays
Arrays.
Installation
npm install @stdlib/array
Usage
var ns = require( '@stdlib/array' );
ns
Arrays.
var o = ns;
// returns {...}
The namespace exports the following array constructors:
ArrayBuffer( size )
: constructor which returns an object used to represent a generic, fixed-length raw binary data buffer.Float32Array()
: typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order.Float64Array()
: typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order.Int16Array()
: typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order.Int32Array()
: typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order.Int8Array()
: typed array constructor which returns a typed array representing an array of twos-complement 8-bit signed integers in the platform byte order.SharedArrayBuffer( size )
: constructor returning an object used to represent a generic, fixed-length raw binary data buffer which can be used to create views of shared memory.Uint16Array()
: typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order.Uint32Array()
: typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order.Uint8Array()
: typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order.Uint8ClampedArray()
: typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order clamped to 0-255.
var arr = new ns.Int32Array( 5 );
// returns <Int32Array>[ 0, 0, 0, 0, 0 ]
Alternatively, use the typedarray
function to create a typed array of a given data type:
typedarray()
: create a typed array.
var arr1 = ns.typedarray( 5 );
// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]
var arr2 = ns.typedarray( 5, 'uint8' );
// returns <Uint8Array>[ 0, 0, 0, 0, 0 ]
The namespace contains functions to create arrays pre-filled with spaced values:
datespace( start, stop[, length][, opts] )
: generate an array of linearly spaced dates.incrspace( start, stop[, increment] )
: generate a linearly spaced numeric array using a provided increment.linspace( start, stop, length[, options] )
: generate a linearly spaced array over a specified interval.logspace( a, b[, length] )
: generate a logarithmically spaced numeric array.
You can use the following functions to retrieve a list of available data types:
dtypes( [kind] )
: list of array data types.complexarrayDataTypes()
: list of complex typed array data types.typedarrayDataTypes()
: list of typed array data types.floatarrayDataTypes()
: list of typed array floating-point data types.intarrayDataTypes()
: list of typed array integer data types.realarrayDataTypes()
: list of typed array real-valued data types.realarrayFloatDataTypes()
: list of typed array real-valued floating-point data types.intarraySignedDataTypes()
: list of typed array signed integer data types.intarrayUnsignedDataTypes()
: list of typed array unsigned integer data types.
Furthermore, the namespace contains utility functions to retrieve a given constructor:
ctors( dtype )
: array constructors.ArrayIndex( x[, options] )
: array index constructor.complexarrayCtors( dtype )
: complex typed array constructors.typedarrayCtors( dtype )
: typed array constructors.floatarrayCtors( dtype )
: floating-point typed array constructors.intarrayCtors( dtype )
: integer-valued typed array constructors.realarrayCtors( dtype )
: typed array constructors.realarrayFloatCtors( dtype )
: real-valued floating-point typed array constructors.intarraySignedCtors( dtype )
: signed integer typed array constructors.intarrayUnsignedCtors( dtype )
: unsigned integer typed array constructors.
var ctor = ns.typedarrayCtors( 'float64' );
// returns <Function>
ctor = ns.typedarrayCtors( 'int' );
// returns null
Lastly, the namespace contains various other functions for dealing with arrays, including functions to convert arrays from one data type to another or to serialize them as JSON and vice versa.
base
: base (i.e., lower-level) array utilities.BooleanArray()
: boolean array.cartesianPower( x, n )
: return the Cartesian power.cartesianProduct( x1, x2 )
: return the Cartesian product.cartesianSquare( x )
: return the Cartesian square.Complex128Array()
: 128-bit complex number array.Complex64Array()
: 64-bit complex number array.convertSame( x, y )
: convert an array to the same data type as a second input array.convert( arr, dtype )
: convert an array to an array of a different data type.DataView( buffer[, byteOffset[, byteLength]] )
: constructor which returns a data view representing a provided array buffer.defaults()
: default array settings.dtype( array )
: return the data type of an array.emptyLike( x[, dtype] )
: create an uninitialized array having the same length and data type as a provided array.empty( length[, dtype] )
: create an uninitialized array having a specified length.filledBy()
: create a filled array according to a provided callback function.filled()
: create a filled array.iterator2array( iterator[, out][, mapFcn[, thisArg]] )
: create (or fill) an array from an iterator.scalar2array( value[, dtype] )
: create a single-element array containing a provided scalar value.fullLike( x, value[, dtype] )
: create a filled array having the same length and data type as a provided array.full( length, value[, dtype] )
: create a filled array having a specified length.minDataType( value )
: determine the minimum array data type of the closest "kind" necessary for storing a provided scalar value.mostlySafeCasts( [dtype] )
: return a list of array data types to which a provided array data type can be safely cast and, for floating-point data types, can be downcast.mskfilter( x, mask )
: apply a mask to a provided input array.mskput( x, mask, values[, options] )
: 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.nansLike( x[, dtype] )
: create an array filled with NaNs and having the same length and data type as a provided array.nans( length[, dtype] )
: create an array filled with NaNs and having a specified length.nextDataType( [dtype] )
: return the next larger array data type of the same kind.oneToLike( x[, dtype] )
: generate a linearly spaced numeric array whose elements increment by1
starting from one and having the same length and data type as a provided input array.oneTo( n[, dtype] )
: generate a linearly spaced numeric array whose elements increment by1
starting from one.onesLike( x[, dtype] )
: create an array filled with ones and having the same length and data type as a provided array.ones( length[, dtype] )
: create an array filled with ones and having a specified length.place( x, mask, values[, options] )
: replace elements of an array with provided values according to a provided mask array.typedarraypool()
: allocate typed arrays from a typed array memory pool.promotionRules( [dtype1, dtype2] )
: return the array data type with the smallest size and closest "kind" to which array data types can be safely cast.put( x, indices, values[, options] )
: replace specified elements of an array with provided values.typedarrayReviver( key, value )
: revive a JSON-serialized typed array.safeCasts( [dtype] )
: return a list of array data types to which a provided array data type can be safely cast.sameKindCasts( [dtype] )
: return a list of array data types to which a provided array data type can be safely cast or cast within the same "kind".shape( arr )
: determine (nested) array dimensions.slice( x[, start[, end]] )
: return a shallow copy of a portion of an array.take( x, indices[, options] )
: take elements from an array.circarray2iterator( src[, options][, mapFcn[, thisArg]] )
: create an iterator which repeatedly iterates over the elements of an array-like object.array2fancy( x[, options] )
: convert an array to an object supporting fancy indexing.array2iteratorRight( src[, mapFcn[, thisArg]] )
: create an iterator from an array-like object, iterating from right to left.array2iterator( src[, mapFcn[, thisArg]] )
: create an iterator from an array-like object.typedarray2json( typedarray )
: return a JSON representation of a typed array.sparsearray2iteratorRight( src[, mapFcn[, thisArg]] )
: create an iterator from a sparse array-like object, iterating from right to left.sparsearray2iterator( src[, mapFcn[, thisArg]] )
: create an iterator from a sparse array-like object.stridedarray2iterator( N, src, stride, offset[, mapFcn[, thisArg]] )
: create an iterator from a strided array-like object.arrayview2iteratorRight( src[, begin[, end]][, mapFcn[, thisArg]] )
: create an iterator from an array-like object view, iterating from right to left.arrayview2iterator( src[, begin[, end]][, mapFcn[, thisArg]] )
: create an iterator from an array-like object view.complexarray()
: create a complex number typed array.realarray()
: create a typed array.zeroToLike( x[, dtype] )
: generate a linearly spaced numeric array whose elements increment by1
starting from zero and having the same length and data type as a provided input array.zeroTo( n[, dtype] )
: generate a linearly spaced numeric array whose elements increment by1
starting from zero.zerosLike( x[, dtype] )
: create a zero-filled array having the same length and data type as a provided array.zeros( length[, dtype] )
: create a zero-filled array having a specified length.
Examples
var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/array' );
console.log( objectKeys( ns ) );
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.