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 on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Multidimensional arrays.
To use in Observable,
ns = require( 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray@umd/browser.js' )To vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:
var ns = require( 'path/to/vendor/umd/ndarray/index.js' )To include the bundle in a webpage,
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/ndarray@umd/browser.js"></script>If no recognized module system is present, access bundle contents via the global scope:
<script type="text/javascript">
(function () {
window.ns;
})();
</script>ndarray namespace.
var o = ns;
// returns {...}The namespace exports the following functions to create multidimensional arrays:
array( [buffer,] [options] ): create a multidimensional array.copy( x[, options] ): copy an input ndarray to a new ndarray having the same shape and data type.ndarray( dtype, buffer, shape, strides, offset, order[, options] ): multidimensional array constructor.emptyLike( x[, options] ): create an uninitialized ndarray having the same shape and data type as a provided ndarray.empty( shape[, options] ): create an uninitialized ndarray having a specified shape and data type.scalar2ndarrayLike( x, value[, options] ): convert a scalar value to a zero-dimensional ndarray having the same data-type as a provided ndarray.scalar2ndarray( value[, options] ): convert a scalar value to a zero-dimensional ndarray.ndarraylike2ndarray( x[, options] ): convert an ndarray-like object to anndarray.ones( shape[, options] ): create a ones-filled ndarray having a specified shape and data type.ndarray2fancy( x[, options] ): convert an ndarray to an object supporting fancy indexing.zerosLike( x[, options] ): create a zero-filled ndarray having the same shape and data type as a provided ndarray.zeros( shape[, options] ): create a zero-filled ndarray having a specified shape and data type.
The namespace exports the following functions to manipulate multidimensional arrays:
broadcastArray( x, shape ): broadcast an ndarray to a specified shape.broadcastArrays( ...arrays ): broadcast ndarrays to a common shape.broadcastScalar( value, shape[, options] ): broadcast a scalar value to an ndarray of a specified shape.colcat( arrays ): concatenate a list of one-dimensional or two-dimensional ndarrays as columns.concat( arrays[, options] ): concatenate a list of ndarrays along a specified ndarray dimension.concat1d( ...arrays ): return a one-dimensional ndarray formed by concatenating provided input arguments.fillBy( x, fcn[, thisArg] ): fill an input ndarray according to a callback function.fillSlice( x, value, ...s[, options] ): fill an inputndarrayview with a specified value.fill( x, value ): fill an inputndarraywith a specified value.flattenBy( x[, options], fcn[, thisArg] ): flatten an ndarray according to a callback function.flattenFromBy( x, dim[, options], fcn[, thisArg] ): flatten an ndarray according to a callback function starting from a specified dimension.flattenFrom( x, dim[, options] ): return a copy of an input ndarray where all dimensions of the input ndarray are flattened starting from a specified dimension.flatten( x[, options] ): return a flattened copy of an input ndarray.fliplr( x ): return a read-only view of an inputndarrayin which the order of elements along the last dimension is reversed.flipud( x ): return a read-only view of an inputndarrayin which the order of elements along the second-to-last dimension is reversed.hconcat( arrays ): concatenate a list of ndarrays along the last dimension.map( x[, options], fcn[, thisArg] ): apply a callback function to elements in an input ndarray and assign results to elements in a new output ndarray.maybeBroadcastArray( x, shape ): broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.maybeBroadcastArrays( arrays ): broadcast ndarrays to a common shape.pop( x[, options] ): return an array containing a read-only truncated view of an inputndarrayand a read-only view of the last element(s) along a specified dimension.prependSingletonDimensions( x, n ): return a read-only view of an input ndarray with a specified number of prepended singleton dimensions.push( x, ...values ): return a one-dimensional ndarray formed by appending provided scalar values to a one-dimensional input ndarray.removeSingletonDimensions( x ): return a read-only view of an input ndarray with singleton dimensions removed.reverseDimension( x, dim ): return a read-only view of an inputndarrayin which the order of elements along a specified dimension is reversed.reverse( x ): return a read-only view of an inputndarrayin which the order of elements along each dimension is reversed.rotr90( x, k ): return a read-only view of a matrix (or a stack of matrices) rotated90degrees clockwise.rowcat( arrays ): concatenate a list of one-dimensional or two-dimensional ndarrays as rows.shift( x[, options] ): return an array containing a read-only truncated view of an inputndarrayand a read-only view of the first element(s) along a specified dimension.sliceAssign( x, y, ...s[, options] ): assign element values from a broadcasted inputndarrayto corresponding elements in an outputndarrayview.sliceDimensionFrom( x, dim, start[, options] ): return a read-only shifted view of an inputndarrayalong a specified dimension.sliceDimensionTo( x, dim, stop[, options] ): return a read-only truncated view of an inputndarrayalong a specified dimension.sliceDimension( x, dim, slice[, options] ): return a read-only view of an inputndarraywhen sliced along a specified dimension.sliceFrom( x, ...start[, options] ): return a read-only shifted view of an input ndarray.sliceTo( x, ...stop[, options] ): return a read-only truncated view of an input ndarray.slice( x, ...s[, options] ): return a read-only view of an inputndarray.spreadDimensions( ndims, x, dims ): return a read-only view of an input ndarray where the dimensions of the input ndarray are expanded to a specified dimensionality by spreading dimensions to specified dimension indices and inserting dimensions of size one for the remaining dimensions.toFlippedlr( x ): return a newndarraywhere the order of elements along the last dimension of an inputndarrayis reversed.toFlippedud( x ): return a newndarraywhere the order of elements along the second-to-last dimension of an inputndarrayis reversed.toReversedDimension( x[, options] ): return a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed.toReversed( x ): return a newndarraywhere the order of elements of an inputndarrayis reversed along each dimension.unshift( x, ...values ): return a one-dimensional ndarray formed by prepending provided scalar values to a one-dimensional input ndarray.vconcat( arrays ): concatenate a list of ndarrays along the second-to-last dimension.ndarrayWith( x, indices, value ): return a new ndarray with the element at a specified index replaced by a provided value.
The namespace exports the following functions to search multidimensional arrays:
anyBy( x[, options], predicate[, thisArg] ): test whether at least one element along one or morendarraydimensions passes a test implemented by a predicate function.any( x[, options] ): test whether at least one element along one or morendarraydimensions is truthy.countFalsy( x[, options] ): count the number of falsy elements along one or morendarraydimensions.countIf( x[, options], predicate[, thisArg] ): count the number of truthy elements along one or morendarraydimensions.countTruthy( x[, options] ): count the number of truthy elements along one or morendarraydimensions.everyBy( x[, options], predicate[, thisArg] ): test whether all elements along one or morendarraydimensions pass a test implemented by a predicate function.every( x[, options] ): test whether every element along one or morendarraydimensions is truthy.filterMap( x[, options], fcn[, thisArg] ): filter and map elements in an input ndarray to elements in a new output ndarray according to a callback function.filter( x[, options], predicate[, thisArg] ): return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.findLast( x[, options], predicate[, thisArg] ): return a new ndarray containing the last elements which pass a test implemented by a predicate function along one or more ndarray dimensions.find( x[, options], predicate[, thisArg] ): return a new ndarray containing the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions.includes( x, searchElement[, options] ): test whether anndarraycontains a specified value along one or more dimensions.reject( x[, options], predicate[, thisArg] ): return a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function.someBy( x, n[, options], predicate[, thisArg] ): test whether at leastnelements along one or morendarraydimensions pass a test implemented by a predicate function.some( x, n[, options] ): test whether at leastnelements along one or morendarraydimensions are truthy.
The namespace exports the following functions to inspect multidimensional arrays:
dataBuffer( x ): return the underlying data buffer of a provided ndarray.dtype( x ): return the data type of a provided ndarray.flag( x, name ): return a specified flag for a provided ndarray.flags( x ): return the flags of a provided ndarray.ndims( x ): return the number of ndarray dimensions.numelDimension( x, dim ): return the size (i.e., number of elements) of a specified dimension for a provided ndarray.numel( x ): return the number of elements in an ndarray.offset( x ): return the index offset specifying the underlying buffer index of the first iterated ndarray element.order( x ): return the layout order of a provided ndarray.shape( x ): return the shape of a provided ndarray.stride( x, dim ): return the stride along a specified dimension for a provided ndarray.strides( x ): return the strides of a provided ndarray.
The namespace exports the following functions to index multidimensional arrays:
at( x[, ...indices] ): return anndarrayelement.ind2sub( shape, idx[, options] ): convert a linear index to an array of subscripts.ndindex( x[, options] ): ndarray index constructor.sub2ind( shape, ...subscripts[, options] ): convert subscripts to a linear index.
The namespace exports the following functions to convert multidimensional arrays:
The namespace exports the following functions for working with multidimensional array data types:
The namespace contains the following sub-namespaces:
The namespace contains the following multidimensional array utility functions:
castingModes(): list of ndarray casting modes.defaults(): default ndarray settings.dispatch( fcns, types, data, nargs, nin, nout ): create an ndarray function interface which performs multiple dispatch.DataType( value[, options] ): data type constructor.dtypes( [kind] ): list of ndarray data types.FancyArray( dtype, buffer, shape, strides, offset, order[, options] ): fancy multidimensional array constructor.forEach( x, fcn[, thisArg] ): invoke a callback function once for each ndarray element.indexModes(): list of ndarray index modes.inputCastingPolicies(): list of input ndarray casting policies.minDataType( value ): determine the minimum ndarray data type of the closest "kind" necessary for storing a provided scalar value.mostlySafeCasts( [dtype] ): return a list of ndarray data types to which a provided ndarray data type can be safely cast and, for floating-point data types, can be downcast.nextDataType( [dtype] ): return the next larger ndarray data type of the same kind.orders(): list of ndarray orders.outputDataTypePolicies(): list of output ndarray data type policies.promotionRules( [dtype1, dtype2] ): return the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be safely cast.safeCasts( [dtype] ): return a list of ndarray data types to which a provided ndarray data type can be safely cast.sameKindCasts( [dtype] ): return a list of ndarray data types to which a provided ndarray data type can be safely cast or cast within the same "kind".ndarray2array( x ): convert an ndarray to a generic array.ndarray2json( x ): serialize an ndarray as a JSON object.ndarray2localeString( x[, locales[, options]] ): serialize an ndarray as a locale-aware string.ndarray2string( x ): serialize an ndarray as a string.
<!DOCTYPE html>
<html lang="en">
<body>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/utils/keys@umd/browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/ndarray@umd/browser.js"></script>
<script type="text/javascript">
(function () {
console.log( objectKeys( ns ) );
})();
</script>
</body>
</html>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.
See LICENSE.
Copyright © 2016-2026. The Stdlib Authors.