Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
stdlib-js/array
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!
Arrays.
npm install @stdlib/array
Alternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use theES Module available on theesmbranch (seeREADME). - If you are using Deno, visit the
denobranch (seeREADME for usage intructions). - For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on the
umdbranch (seeREADME).
Thebranches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
varns=require('@stdlib/array');
Arrays.
varo=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.
vararr=newns.Int32Array(5);// returns <Int32Array>[ 0, 0, 0, 0, 0 ]
Alternatively, use thetypedarray function to create a typed array of a given data type:
typedarray():create a typed array.
vararr1=ns.typedarray(5);// returns <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0 ]vararr2=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.
varctor=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.byteOrders():list of byte orders.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.fixedEndianFactory( dtype ):return a typed array constructor for creating typed arrays having a specified byte order.Float32ArrayFE():typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in a specified byte order.Float64ArrayFE():typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in a specified byte order.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.littleEndianFactory( dtype ):return a typed array constructor for creating typed arrays stored in little-endian byte order.Float32ArrayLE():typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in little-endian byte order.Float64ArrayLE():typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in little-endian byte order.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 by1starting 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 by1starting 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 besafely 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 by1starting 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 by1starting 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.
varobjectKeys=require('@stdlib/utils/keys');varns=require('@stdlib/array');console.log(objectKeys(ns));
This package is part ofstdlib, 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 developstdlib, see the main projectrepository.
SeeLICENSE.
Copyright © 2016-2025. The StdlibAuthors.
About
Arrays.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.