Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stdlib-js/ndarray
Multidimensional arrays.
https://github.com/stdlib-js/ndarray
array buffer data javascript matrix multidimensional namespace ndarray node node-js nodejs ns stdlib structures tensor typed typed-array types vector
Last synced: 1 day ago
JSON representation
Multidimensional arrays.
- Host: GitHub
- URL: https://github.com/stdlib-js/ndarray
- Owner: stdlib-js
- License: apache-2.0
- Created: 2021-04-22T14:56:16.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-13T00:16:28.000Z (11 days ago)
- Last Synced: 2025-01-13T01:23:15.023Z (11 days ago)
- Topics: array, buffer, data, javascript, matrix, multidimensional, namespace, ndarray, node, node-js, nodejs, ns, stdlib, structures, tensor, typed, typed-array, types, vector
- Language: C
- Homepage: https://github.com/stdlib-js/stdlib
- Size: 123 MB
- Stars: 10
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Security: SECURITY.md
Awesome Lists containing this project
README
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!
# ndarray
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url]
> Multidimensional arrays.
## Installation
```bash
npm install @stdlib/ndarray
```Alternatively,
- To load the package in a website via a `script` tag without installation and bundlers, use the [ES Module][es-module] available on the [`esm`][esm-url] branch (see [README][esm-readme]).
- If you are using Deno, visit the [`deno`][deno-url] branch (see [README][deno-readme] for usage intructions).
- For use in Observable, or in browser/node environments, use the [Universal Module Definition (UMD)][umd] build available on the [`umd`][umd-url] branch (see [README][umd-readme]).The [branches.md][branches-url] 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.
## Usage
```javascript
var ns = require( '@stdlib/ndarray' );
```#### ns
ndarray namespace.
```javascript
var o = ns;
// returns {...}
```The namespace exports the following functions to create multidimensional arrays:
- [`array( [buffer,] [options] )`][@stdlib/ndarray/array]: create a multidimensional array.
- [`ndarray( dtype, buffer, shape, strides, offset, order[, options] )`][@stdlib/ndarray/ctor]: multidimensional array constructor.The namespace contains the following sub-namespaces:
- [`base`][@stdlib/ndarray/base]: base ndarray.
- [`iter`][@stdlib/ndarray/iter]: multidimensional array iterators.In addition, the namespace contains the following multidimensional array utility functions:
- [`at( x[, ...indices] )`][@stdlib/ndarray/at]: return an `ndarray` element.
- [`broadcastArray( x, shape )`][@stdlib/ndarray/broadcast-array]: broadcast an ndarray to a specified shape.
- [`broadcastArrays( ...arrays )`][@stdlib/ndarray/broadcast-arrays]: broadcast ndarrays to a common shape.
- [`castingModes()`][@stdlib/ndarray/casting-modes]: list of ndarray casting modes.
- [`dataBuffer( x )`][@stdlib/ndarray/data-buffer]: return the underlying data buffer of a provided ndarray.
- [`defaults()`][@stdlib/ndarray/defaults]: default ndarray settings.
- [`dispatch( fcns, types, data, nargs, nin, nout )`][@stdlib/ndarray/dispatch]: create an ndarray function interface which performs multiple dispatch.
- [`dtype( x )`][@stdlib/ndarray/dtype]: return the data type of a provided ndarray.
- [`dtypes( [kind] )`][@stdlib/ndarray/dtypes]: list of ndarray data types.
- [`emptyLike( x[, options] )`][@stdlib/ndarray/empty-like]: create an uninitialized ndarray having the same shape and data type as a provided ndarray.
- [`empty( shape[, options] )`][@stdlib/ndarray/empty]: create an uninitialized ndarray having a specified shape and data type.
- [`FancyArray( dtype, buffer, shape, strides, offset, order[, options] )`][@stdlib/ndarray/fancy]: fancy multidimensional array constructor.
- [`filterMap( x[, options], fcn[, thisArg] )`][@stdlib/ndarray/filter-map]: 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] )`][@stdlib/ndarray/filter]: return a shallow copy of an ndarray containing only those elements which pass a test implemented by a predicate function.
- [`flag( x, name )`][@stdlib/ndarray/flag]: return a specified flag for a provided ndarray.
- [`flags( x )`][@stdlib/ndarray/flags]: return the flags of a provided ndarray.
- [`forEach( x, fcn[, thisArg] )`][@stdlib/ndarray/for-each]: invoke a callback function once for each ndarray element.
- [`scalar2ndarray( value[, options] )`][@stdlib/ndarray/from-scalar]: convert a scalar value to a zero-dimensional ndarray.
- [`ind2sub( shape, idx[, options] )`][@stdlib/ndarray/ind2sub]: convert a linear index to an array of subscripts.
- [`indexModes()`][@stdlib/ndarray/index-modes]: list of ndarray index modes.
- [`ndindex( x[, options] )`][@stdlib/ndarray/index]: ndarray index constructor.
- [`map( x[, options], fcn[, thisArg] )`][@stdlib/ndarray/map]: apply a callback function to elements in an input ndarray and assign results to elements in a new output ndarray.
- [`maybeBroadcastArray( x, shape )`][@stdlib/ndarray/maybe-broadcast-array]: broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.
- [`maybeBroadcastArrays( arrays )`][@stdlib/ndarray/maybe-broadcast-arrays]: broadcast ndarrays to a common shape.
- [`minDataType( value )`][@stdlib/ndarray/min-dtype]: determine the minimum ndarray data type of the closest "kind" necessary for storing a provided scalar value.
- [`mostlySafeCasts( [dtype] )`][@stdlib/ndarray/mostly-safe-casts]: 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.
- [`ndarraylike2ndarray( x[, options] )`][@stdlib/ndarray/ndarraylike2ndarray]: convert an ndarray-like object to an `ndarray`.
- [`ndims( x )`][@stdlib/ndarray/ndims]: return the number of ndarray dimensions.
- [`nextDataType( [dtype] )`][@stdlib/ndarray/next-dtype]: return the next larger ndarray data type of the same kind.
- [`numelDimension( x, dim )`][@stdlib/ndarray/numel-dimension]: return the size (i.e., number of elements) of a specified dimension for a provided ndarray.
- [`numel( x )`][@stdlib/ndarray/numel]: return the number of elements in an ndarray.
- [`offset( x )`][@stdlib/ndarray/offset]: return the index offset specifying the underlying buffer index of the first iterated ndarray element.
- [`order( x )`][@stdlib/ndarray/order]: return the layout order of a provided ndarray.
- [`orders()`][@stdlib/ndarray/orders]: list of ndarray orders.
- [`outputDataTypePolicies()`][@stdlib/ndarray/output-dtype-policies]: list of output ndarray data type policies.
- [`promotionRules( [dtype1, dtype2] )`][@stdlib/ndarray/promotion-rules]: return the ndarray data type with the smallest size and closest "kind" to which ndarray data types can be **safely** cast.
- [`reject( x[, options], predicate[, thisArg] )`][@stdlib/ndarray/reject]: return a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function.
- [`safeCasts( [dtype] )`][@stdlib/ndarray/safe-casts]: return a list of ndarray data types to which a provided ndarray data type can be safely cast.
- [`sameKindCasts( [dtype] )`][@stdlib/ndarray/same-kind-casts]: return a list of ndarray data types to which a provided ndarray data type can be safely cast or cast within the same "kind".
- [`shape( x )`][@stdlib/ndarray/shape]: return the shape of a provided ndarray.
- [`sliceAssign( x, y, ...s[, options] )`][@stdlib/ndarray/slice-assign]: assign element values from a broadcasted input `ndarray` to corresponding elements in an output `ndarray` view.
- [`sliceDimensionFrom( x, dim, start[, options] )`][@stdlib/ndarray/slice-dimension-from]: return a read-only shifted view of an input `ndarray` along a specified dimension.
- [`sliceDimensionTo( x, dim, stop[, options] )`][@stdlib/ndarray/slice-dimension-to]: return a read-only truncated view of an input `ndarray` along a specified dimension.
- [`sliceDimension( x, dim, slice[, options] )`][@stdlib/ndarray/slice-dimension]: return a read-only view of an input `ndarray` when sliced along a specified dimension.
- [`sliceFrom( x, ...start[, options] )`][@stdlib/ndarray/slice-from]: return a read-only shifted view of an input ndarray.
- [`sliceTo( x, ...stop[, options] )`][@stdlib/ndarray/slice-to]: return a read-only truncated view of an input ndarray.
- [`slice( x, ...s[, options] )`][@stdlib/ndarray/slice]: return a read-only view of an input `ndarray`.
- [`stride( x, dim )`][@stdlib/ndarray/stride]: return the stride along a specified dimension for a provided ndarray.
- [`strides( x )`][@stdlib/ndarray/strides]: return the strides of a provided ndarray.
- [`sub2ind( shape, ...subscripts[, options] )`][@stdlib/ndarray/sub2ind]: convert subscripts to a linear index.
- [`ndarray2array( x )`][@stdlib/ndarray/to-array]: convert an ndarray to a generic array.
- [`ndarray2fancy( x[, options] )`][@stdlib/ndarray/to-fancy]: convert an ndarray to an object supporting fancy indexing.
- [`ndarray2json( x )`][@stdlib/ndarray/to-json]: serialize an ndarray as a JSON object.
- [`zerosLike( x[, options] )`][@stdlib/ndarray/zeros-like]: create a zero-filled ndarray having the same shape and data type as a provided ndarray.
- [`zeros( shape[, options] )`][@stdlib/ndarray/zeros]: create a zero-filled ndarray having a specified shape and data type.## Examples
```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/ndarray' );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-2025. The Stdlib [Authors][stdlib-authors].
[npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray.svg
[npm-url]: https://npmjs.org/package/@stdlib/ndarray[test-image]: https://github.com/stdlib-js/ndarray/actions/workflows/test.yml/badge.svg?branch=main
[test-url]: https://github.com/stdlib-js/ndarray/actions/workflows/test.yml?query=branch:main[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray/main.svg
[coverage-url]: https://codecov.io/github/stdlib-js/ndarray?branch=main[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im[stdlib]: https://github.com/stdlib-js/stdlib
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
[umd]: https://github.com/umdjs/umd
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules[deno-url]: https://github.com/stdlib-js/ndarray/tree/deno
[deno-readme]: https://github.com/stdlib-js/ndarray/blob/deno/README.md
[umd-url]: https://github.com/stdlib-js/ndarray/tree/umd
[umd-readme]: https://github.com/stdlib-js/ndarray/blob/umd/README.md
[esm-url]: https://github.com/stdlib-js/ndarray/tree/esm
[esm-readme]: https://github.com/stdlib-js/ndarray/blob/esm/README.md
[branches-url]: https://github.com/stdlib-js/ndarray/blob/main/branches.md[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray/main/LICENSE
[@stdlib/ndarray/at]: https://github.com/stdlib-js/ndarray/tree/main/at
[@stdlib/ndarray/broadcast-array]: https://github.com/stdlib-js/ndarray/tree/main/broadcast-array
[@stdlib/ndarray/broadcast-arrays]: https://github.com/stdlib-js/ndarray/tree/main/broadcast-arrays
[@stdlib/ndarray/casting-modes]: https://github.com/stdlib-js/ndarray/tree/main/casting-modes
[@stdlib/ndarray/data-buffer]: https://github.com/stdlib-js/ndarray/tree/main/data-buffer
[@stdlib/ndarray/defaults]: https://github.com/stdlib-js/ndarray/tree/main/defaults
[@stdlib/ndarray/dispatch]: https://github.com/stdlib-js/ndarray/tree/main/dispatch
[@stdlib/ndarray/dtype]: https://github.com/stdlib-js/ndarray/tree/main/dtype
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
[@stdlib/ndarray/empty-like]: https://github.com/stdlib-js/ndarray/tree/main/empty-like
[@stdlib/ndarray/empty]: https://github.com/stdlib-js/ndarray/tree/main/empty
[@stdlib/ndarray/fancy]: https://github.com/stdlib-js/ndarray/tree/main/fancy
[@stdlib/ndarray/filter-map]: https://github.com/stdlib-js/ndarray/tree/main/filter-map
[@stdlib/ndarray/filter]: https://github.com/stdlib-js/ndarray/tree/main/filter
[@stdlib/ndarray/flag]: https://github.com/stdlib-js/ndarray/tree/main/flag
[@stdlib/ndarray/flags]: https://github.com/stdlib-js/ndarray/tree/main/flags
[@stdlib/ndarray/for-each]: https://github.com/stdlib-js/ndarray/tree/main/for-each
[@stdlib/ndarray/from-scalar]: https://github.com/stdlib-js/ndarray/tree/main/from-scalar
[@stdlib/ndarray/ind2sub]: https://github.com/stdlib-js/ndarray/tree/main/ind2sub
[@stdlib/ndarray/index-modes]: https://github.com/stdlib-js/ndarray/tree/main/index-modes
[@stdlib/ndarray/index]: https://github.com/stdlib-js/ndarray/tree/main/index
[@stdlib/ndarray/map]: https://github.com/stdlib-js/ndarray/tree/main/map
[@stdlib/ndarray/maybe-broadcast-array]: https://github.com/stdlib-js/ndarray/tree/main/maybe-broadcast-array
[@stdlib/ndarray/maybe-broadcast-arrays]: https://github.com/stdlib-js/ndarray/tree/main/maybe-broadcast-arrays
[@stdlib/ndarray/min-dtype]: https://github.com/stdlib-js/ndarray/tree/main/min-dtype
[@stdlib/ndarray/mostly-safe-casts]: https://github.com/stdlib-js/ndarray/tree/main/mostly-safe-casts
[@stdlib/ndarray/ndarraylike2ndarray]: https://github.com/stdlib-js/ndarray/tree/main/ndarraylike2ndarray
[@stdlib/ndarray/ndims]: https://github.com/stdlib-js/ndarray/tree/main/ndims
[@stdlib/ndarray/next-dtype]: https://github.com/stdlib-js/ndarray/tree/main/next-dtype
[@stdlib/ndarray/numel-dimension]: https://github.com/stdlib-js/ndarray/tree/main/numel-dimension
[@stdlib/ndarray/numel]: https://github.com/stdlib-js/ndarray/tree/main/numel
[@stdlib/ndarray/offset]: https://github.com/stdlib-js/ndarray/tree/main/offset
[@stdlib/ndarray/order]: https://github.com/stdlib-js/ndarray/tree/main/order
[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray/tree/main/orders
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray/tree/main/output-dtype-policies
[@stdlib/ndarray/promotion-rules]: https://github.com/stdlib-js/ndarray/tree/main/promotion-rules
[@stdlib/ndarray/reject]: https://github.com/stdlib-js/ndarray/tree/main/reject
[@stdlib/ndarray/safe-casts]: https://github.com/stdlib-js/ndarray/tree/main/safe-casts
[@stdlib/ndarray/same-kind-casts]: https://github.com/stdlib-js/ndarray/tree/main/same-kind-casts
[@stdlib/ndarray/shape]: https://github.com/stdlib-js/ndarray/tree/main/shape
[@stdlib/ndarray/slice-assign]: https://github.com/stdlib-js/ndarray/tree/main/slice-assign
[@stdlib/ndarray/slice-dimension-from]: https://github.com/stdlib-js/ndarray/tree/main/slice-dimension-from
[@stdlib/ndarray/slice-dimension-to]: https://github.com/stdlib-js/ndarray/tree/main/slice-dimension-to
[@stdlib/ndarray/slice-dimension]: https://github.com/stdlib-js/ndarray/tree/main/slice-dimension
[@stdlib/ndarray/slice-from]: https://github.com/stdlib-js/ndarray/tree/main/slice-from
[@stdlib/ndarray/slice-to]: https://github.com/stdlib-js/ndarray/tree/main/slice-to
[@stdlib/ndarray/slice]: https://github.com/stdlib-js/ndarray/tree/main/slice
[@stdlib/ndarray/stride]: https://github.com/stdlib-js/ndarray/tree/main/stride
[@stdlib/ndarray/strides]: https://github.com/stdlib-js/ndarray/tree/main/strides
[@stdlib/ndarray/sub2ind]: https://github.com/stdlib-js/ndarray/tree/main/sub2ind
[@stdlib/ndarray/to-array]: https://github.com/stdlib-js/ndarray/tree/main/to-array
[@stdlib/ndarray/to-fancy]: https://github.com/stdlib-js/ndarray/tree/main/to-fancy
[@stdlib/ndarray/to-json]: https://github.com/stdlib-js/ndarray/tree/main/to-json
[@stdlib/ndarray/zeros-like]: https://github.com/stdlib-js/ndarray/tree/main/zeros-like
[@stdlib/ndarray/zeros]: https://github.com/stdlib-js/ndarray/tree/main/zeros
[@stdlib/ndarray/base]: https://github.com/stdlib-js/ndarray/tree/main/base
[@stdlib/ndarray/iter]: https://github.com/stdlib-js/ndarray/tree/main/iter
[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray/tree/main/array
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor