# Arrays [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url] > Arrays.
## Installation ```bash npm install @stdlib/array ```
## Usage ```javascript var ns = require( '@stdlib/array' ); ``` #### ns Arrays. ```javascript var o = ns; // returns {...} ``` The namespace exports the following array constructors:
- [`ArrayBuffer( size )`][@stdlib/array/buffer]: constructor which returns an object used to represent a generic, fixed-length raw binary data buffer. - [`Float32Array()`][@stdlib/array/float32]: typed array constructor which returns a typed array representing an array of single-precision floating-point numbers in the platform byte order. - [`Float64Array()`][@stdlib/array/float64]: typed array constructor which returns a typed array representing an array of double-precision floating-point numbers in the platform byte order. - [`Int16Array()`][@stdlib/array/int16]: typed array constructor which returns a typed array representing an array of twos-complement 16-bit signed integers in the platform byte order. - [`Int32Array()`][@stdlib/array/int32]: typed array constructor which returns a typed array representing an array of twos-complement 32-bit signed integers in the platform byte order. - [`Int8Array()`][@stdlib/array/int8]: 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 )`][@stdlib/array/shared-buffer]: 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()`][@stdlib/array/uint16]: typed array constructor which returns a typed array representing an array of 16-bit unsigned integers in the platform byte order. - [`Uint32Array()`][@stdlib/array/uint32]: typed array constructor which returns a typed array representing an array of 32-bit unsigned integers in the platform byte order. - [`Uint8Array()`][@stdlib/array/uint8]: typed array constructor which returns a typed array representing an array of 8-bit unsigned integers in the platform byte order. - [`Uint8ClampedArray()`][@stdlib/array/uint8c]: 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.
```javascript var arr = new ns.Int32Array( 5 ); // returns [ 0, 0, 0, 0, 0 ] ``` Alternatively, use the `typedarray` function to create a typed array of a given data type:
- [`typedarray()`][@stdlib/array/typed]: create a typed array.
```javascript var arr1 = ns.typedarray( 5 ); // returns [ 0.0, 0.0, 0.0, 0.0, 0.0 ] var arr2 = ns.typedarray( 5, 'uint8' ); // returns [ 0, 0, 0, 0, 0 ] ``` The namespace contains functions to create arrays pre-filled with spaced values:
- [`datespace( start, stop[, length][, opts] )`][@stdlib/array/datespace]: generate an array of linearly spaced dates. - [`incrspace( start, stop[, increment] )`][@stdlib/array/incrspace]: generate a linearly spaced numeric array using a provided increment. - [`linspace( start, stop[, length] )`][@stdlib/array/linspace]: generate a linearly spaced numeric array. - [`logspace( a, b[, length] )`][@stdlib/array/logspace]: generate a logarithmically spaced numeric array.
You can use the following functions to retrieve a list of available data types:
- [`arrayDataTypes()`][@stdlib/array/dtypes]: list of array data types. - [`typedarrayComplexDataTypes()`][@stdlib/array/typed-complex-dtypes]: list of complex typed array data types. - [`typedarrayDataTypes()`][@stdlib/array/typed-dtypes]: list of typed array data types.
```javascript var DTYPES = ns.arrayDataTypes(); // returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c' ] ``` Furthermore, the namespace contains utility functions to retrieve a given constructor:
- [`arrayCtors( dtype )`][@stdlib/array/ctors]: array constructors. - [`typedarrayComplexCtors( dtype )`][@stdlib/array/typed-complex-ctors]: complex typed array constructors. - [`typedarrayCtors( dtype )`][@stdlib/array/typed-ctors]: typed array constructors.
```javascript var ctor = ns.typedarrayCtors( 'float64' ); // returns 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.
- [`Complex128Array()`][@stdlib/array/complex128]: 128-bit complex number array. - [`Complex64Array()`][@stdlib/array/complex64]: 64-bit complex number array. - [`convertArraySame( x, y )`][@stdlib/array/convert-same]: convert an array to the same data type as a second input array. - [`convertArray( arr, dtype )`][@stdlib/array/convert]: convert an array to an array of a different data type. - [`DataView( buffer[, byteOffset[, byteLength]] )`][@stdlib/array/dataview]: constructor which returns a data view representing a provided array buffer. - [`arrayDataType( array )`][@stdlib/array/dtype]: return the data type of an array. - [`filledarray()`][@stdlib/array/filled]: create a filled array. - [`iterator2array( iterator[, out][, mapFcn[, thisArg]] )`][@stdlib/array/from-iterator]: create (or fill) an array from an iterator. - [`arrayMinDataType( value )`][@stdlib/array/min-dtype]: determine the minimum array data type of the closest "kind" necessary for storing a provided scalar value. - [`arrayNextDataType( [dtype] )`][@stdlib/array/next-dtype]: return the next larger array data type of the same kind. - [`typedarraypool()`][@stdlib/array/pool]: allocate typed arrays from a typed array memory pool. - [`arrayPromotionRules( [dtype1, dtype2] )`][@stdlib/array/promotion-rules]: return the array data type with the smallest size and closest "kind" to which array data types can be **safely** cast. - [`reviveTypedArray( key, value )`][@stdlib/array/reviver]: revive a JSON-serialized typed array. - [`arraySafeCasts( [dtype] )`][@stdlib/array/safe-casts]: return a list of array data types to which a provided array data type can be safely cast. - [`arraySameKindCasts( [dtype] )`][@stdlib/array/same-kind-casts]: return a list of array data types to which a provided array data type can be safely cast or cast within the same "kind". - [`arrayShape( arr )`][@stdlib/array/shape]: determine (nested) array dimensions. - [`circarray2iterator( src[, options][, mapFcn[, thisArg]] )`][@stdlib/array/to-circular-iterator]: create an iterator which repeatedly iterates over the elements of an array-like object. - [`array2iteratorRight( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-iterator-right]: create an iterator from an array-like object, iterating from right to left. - [`array2iterator( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-iterator]: create an iterator from an array-like object. - [`typedarray2json( typedarray )`][@stdlib/array/to-json]: return a JSON representation of a typed array. - [`sparsearray2iteratorRight( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-sparse-iterator-right]: create an iterator from a sparse array-like object, iterating from right to left. - [`sparsearray2iterator( src[, mapFcn[, thisArg]] )`][@stdlib/array/to-sparse-iterator]: create an iterator from a sparse array-like object. - [`stridedarray2iterator( N, src, stride, offset[, mapFcn[, thisArg]] )`][@stdlib/array/to-strided-iterator]: create an iterator from a strided array-like object. - [`arrayview2iteratorRight( src[, begin[, end]][, mapFcn[, thisArg]] )`][@stdlib/array/to-view-iterator-right]: create an iterator from an array-like object view, iterating from right to left. - [`arrayview2iterator( src[, begin[, end]][, mapFcn[, thisArg]] )`][@stdlib/array/to-view-iterator]: create an iterator from an array-like object view.
## Examples ```javascript var objectKeys = require( '@stdlib/utils/keys' ); var ns = require( '@stdlib/array' ); console.log( objectKeys( ns ) ); ```
* * * ## Notice This package is part of [stdlib][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][stdlib], see the main project [repository][stdlib]. #### Community [![Chat][chat-image]][chat-url] --- ## License See [LICENSE][stdlib-license]. ## Copyright Copyright © 2016-2021. The Stdlib [Authors][stdlib-authors].