@stdlib/ndarray-array

Multidimensional arrays.

https://github.com/stdlib-js/ndarray-array

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.8%) to scientific vocabulary

Keywords

array data dimensions dims javascript multidimensional node node-js nodejs stdlib structure typed typed-array types

Keywords from Contributors

iterator tokenizer accumulator name capitals reduced normal assert strided property
Last synced: 6 months ago · JSON representation ·

Repository

Multidimensional arrays.

Basic Info
Statistics
  • Stars: 4
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
array data dimensions dims javascript multidimensional node node-js nodejs stdlib structure typed typed-array types
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Security

README.md

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

NPM version Build Status Coverage Status <!-- dependencies -->

Create a multidimensional array.

## Installation ```bash npm install @stdlib/ndarray-array ``` 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 array = require( '@stdlib/ndarray-array' ); ``` #### array( \[buffer,] \[options] ) Returns a multidimensional array. ```javascript // Create a 2x2 matrix: var arr = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); // returns ``` To initialize multidimensional array data, provide a `buffer` argument, which may be a [generic array][@stdlib/array/generic], [typed array][@stdlib/array/typed], [Buffer][@stdlib/buffer/ctor], or [ndarray][@stdlib/ndarray/ctor]. ```javascript var Float64Array = require( '@stdlib/array-float64' ); var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); // Create an ndarray from a generic array linear data buffer: var arr = array( [ 1.0, 2.0, 3.0, 4.0 ], { 'shape': [ 2, 2 ] } ); // returns // Create an ndarray from a typed array linear data buffer: arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // returns // Create an ndarray as a view over a Buffer: arr = array( allocUnsafe( 4 ), { 'shape': [ 2, 2 ] } ); // returns // Create an ndarray from another ndarray: arr = array( array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) ); // returns ``` The function accepts the following options: - **buffer**: data source. If provided along with a `buffer` argument, the argument takes precedence. - **dtype**: underlying storage [data type][@stdlib/ndarray/dtypes]. If not specified and a data source is provided, the data type is inferred from the provided data source. If an input data source is not of the same type, this option specifies the data type to which to cast the input data. For non-[ndarray][@stdlib/ndarray/ctor] generic array data sources, the function casts generic array data elements to the default data type. In order to prevent this cast, the `dtype` option **must** be explicitly set to `'generic'`. Any time a cast is required, the `copy` option is set to `true`, as memory must be copied from the data source to an output data buffer. Default: `'float64'`. - **order**: specifies the memory layout of the data source as either row-major (C-style) or column-major (Fortran-style). The option may be one of the following values: - `'row-major'`: the order of the returned array is row-major. - `'column-major'`: the order of the returned array is column-major. - `'any'`: if a data source is column-major and not row-major, the order of the returned array is column-major; otherwise, the order of the returned array is row-major. - `'same'`: the order of the returned array matches the order of an input data source. Note that specifying an order which differs from the order of a provided data source does **not** entail a conversion from one memory layout to another. In short, this option is descriptive, not prescriptive. Default: `'row-major'`. - **shape**: array shape (dimensions). If a shape is not specified, the function attempts to infer a shape based on a provided data source. For example, if provided a nested array, the function resolves nested array dimensions. If provided a multidimensional array data source, the function uses the array's associated shape. For most use cases, such inference suffices. For the remaining use cases, specifying a shape is necessary. For example, provide a shape to create a multidimensional array view over a linear data buffer, ignoring any existing shape meta data associated with a provided data source. - **flatten**: boolean indicating whether to automatically flatten generic array data sources. If an array shape is not specified, the shape is inferred from the dimensions of nested arrays prior to flattening. If a use case requires partial flattening, partially flatten **prior** to invoking this function and set the option value to `false` to prevent further flattening during invocation. Default: `true`. - **copy**: boolean indicating whether to (shallow) copy source data to a new data buffer. The function does **not** perform a deep copy. To prevent undesired shared changes in state for generic arrays containing objects, perform a deep copy **prior** to invoking this function. Default: `false`. - **ndmin**: specifies the minimum number of dimensions. If an array shape has fewer dimensions than required by `ndmin`, the function **prepends** singleton dimensions to the array shape in order to satisfy the dimensions requirement. Default: `0`. - **casting**: specifies the casting rule used to determine acceptable casts. The option may be one of the following values: - `'none'`: only allow casting between identical types. - `'equiv'`: allow casting between identical and byte swapped types. - `'safe'`: only allow "safe" casts. - `'mostly-safe'`: allow "safe" casts and, for floating-point data types, downcasts. - `'same-kind'`: allow "safe" casts and casts within the same kind (e.g., between signed integers or between floats). - `'unsafe'`: allow casting between all types (including between integers and floats). Default: `'safe'`. - **mode**: specifies how to handle indices which exceed array dimensions. - `'throw'`: specifies that an [ndarray][@stdlib/ndarray/ctor] instance should throw an error when an index exceeds array dimensions. - `'normalize'`: specifies that an [ndarray][@stdlib/ndarray/ctor] instance should normalize negative indices and throw an error when an index exceeds array dimensions. - `'wrap'`: specifies that an [ndarray][@stdlib/ndarray/ctor] instance should wrap around an index exceeding array dimensions using modulo arithmetic. - `'clamp'`: specifies that an [ndarray][@stdlib/ndarray/ctor] instance should set an index exceeding array dimensions to either `0` (minimum index) or the maximum index. Default: `'throw'`. - **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions. If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. Default: `[ options.mode ]`. - **readonly**: boolean indicating whether an [ndarray][@stdlib/ndarray/ctor] instance should be **read-only**. Default: `false`. By default, an [ndarray][@stdlib/ndarray/ctor] instance **throws** when provided an index which exceeds array dimensions. To support alternative indexing behavior, set the `mode` option, which will affect all public methods for getting and setting array elements. ```javascript var opts = { 'mode': 'clamp' }; var arr = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ], opts ); // returns // Attempt to access an out-of-bounds linear index (clamped): var v = arr.iget( 10 ); // returns 4.0 ``` By default, the `mode` option is applied to subscripts which exceed array dimensions. To specify behavior for each dimension, set the `submode` option. ```javascript var opts = { 'submode': [ 'wrap', 'clamp' ] }; var arr = array( [ [[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]] ], opts ); // returns // Attempt to access out-of-bounds subscripts: var v = arr.get( -2, 10, -1 ); // linear index: 3 // returns 4.0 ``` By default, the function automatically flattens [generic array][@stdlib/array/generic] data sources. To prevent flattening, set the `flatten` option to `false`. ```javascript var opts = { 'flatten': false, 'dtype': 'generic' }; // Create a generic array which will serve as our ndarray data source: var buf = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]; // Create a 2-element vector: var arr = array( buf, opts ); // returns // Retrieve the first vector element: var v = arr.get( 0 ); // returns [ 1.0, 2.0 ] var bool = ( v === buf[ 0 ] ); // returns true ```
* * * ## Notes - The number of elements in a data source `buffer` **must** agree with a specified array shape (i.e., the function assumes a single-segment contiguous [ndarray][@stdlib/ndarray/ctor]). To create arbitrary multidimensional views over linear data buffers, use a [lower-level constructor][@stdlib/ndarray/ctor]. - The function supports arbitrary casting between data types. Note, however, that casting from a larger data type to a smaller data type (e.g., `int32` to `int8`) and between signed and unsigned types of the same size should be considered **unsafe**.
* * * ## Examples ```javascript var array = require( '@stdlib/ndarray-array' ); // Create a 4-dimensional array containing single-precision floating-point numbers: var arr = array({ 'dtype': 'float32', 'shape': [ 3, 3, 3, 3 ] }); // Retrieve an array value: var v = arr.get( 1, 2, 1, 2 ); // returns 0.0 // Set an array value: arr.set( 1, 2, 1, 2, 10.0 ); // Retrieve the array value: v = arr.get( 1, 2, 1, 2 ); // returns 10.0 // Serialize the array as a string: var str = arr.toString(); // returns "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" // Serialize the array as JSON: str = JSON.stringify( arr.toJSON() ); // e.g., returns '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' ```
* * * ## 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].

Owner

  • Name: stdlib
  • Login: stdlib-js
  • Kind: organization

Standard library for JavaScript.

Citation (CITATION.cff)

cff-version: 1.2.0
title: stdlib
message: >-
  If you use this software, please cite it using the
  metadata from this file.

type: software

authors:
  - name: The Stdlib Authors
    url: https://github.com/stdlib-js/stdlib/graphs/contributors

repository-code: https://github.com/stdlib-js/stdlib
url: https://stdlib.io

abstract: |
  Standard library for JavaScript and Node.js.

keywords:
  - JavaScript
  - Node.js
  - TypeScript
  - standard library
  - scientific computing
  - numerical computing
  - statistical computing

license: Apache-2.0 AND BSL-1.0

date-released: 2016

GitHub Events

Total
  • Push event: 42
Last Year
  • Push event: 42

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 64
  • Total Committers: 2
  • Avg Commits per committer: 32.0
  • Development Distribution Score (DDS): 0.031
Past Year
  • Commits: 6
  • Committers: 1
  • Avg Commits per committer: 6.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
stdlib-bot n****y@s****o 62
Philipp Burckhardt p****t@o****m 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • npm 607 last-month
  • Total dependent packages: 72
  • Total dependent repositories: 38
  • Total versions: 12
  • Total maintainers: 4
npmjs.org: @stdlib/ndarray-array

Multidimensional arrays.

  • Homepage: https://stdlib.io
  • License: Apache-2.0
  • Latest release: 0.2.1
    published almost 2 years ago
  • Versions: 12
  • Dependent Packages: 72
  • Dependent Repositories: 38
  • Downloads: 607 Last month
Rankings
Dependent packages count: 0.5%
Dependent repos count: 2.1%
Downloads: 2.2%
Average: 6.7%
Stargazers count: 13.2%
Forks count: 15.4%
Funding
  • type: opencollective
  • url: https://opencollective.com/stdlib
Last synced: 6 months ago

Dependencies

package.json npm
  • @stdlib/array-float32 ^0.0.x development
  • @stdlib/bench ^0.0.x development
  • istanbul ^0.4.1 development
  • tap-spec 5.x.x development
  • tape git+https://github.com/kgryte/tape.git#fix/globby development
  • @stdlib/array-shape ^0.0.x
  • @stdlib/assert-has-own-property ^0.0.x
  • @stdlib/assert-is-array ^0.0.x
  • @stdlib/assert-is-boolean ^0.0.x
  • @stdlib/assert-is-ndarray-like ^0.0.x
  • @stdlib/assert-is-nonnegative-integer ^0.0.x
  • @stdlib/assert-is-plain-object ^0.0.x
  • @stdlib/buffer-alloc-unsafe ^0.0.x
  • @stdlib/constants-float64-pinf ^0.0.x
  • @stdlib/math-base-assert-is-integer ^0.0.x
  • @stdlib/math-base-special-abs ^0.0.x
  • @stdlib/ndarray-base-assert-is-allowed-data-type-cast ^0.0.x
  • @stdlib/ndarray-base-assert-is-casting-mode ^0.0.x
  • @stdlib/ndarray-base-assert-is-data-type ^0.0.x
  • @stdlib/ndarray-base-assert-is-order ^0.0.x
  • @stdlib/ndarray-base-buffer ^0.0.x
  • @stdlib/ndarray-base-buffer-ctors ^0.0.x
  • @stdlib/ndarray-base-buffer-dtype ^0.0.x
  • @stdlib/ndarray-base-numel ^0.0.x
  • @stdlib/ndarray-base-shape2strides ^0.0.x
  • @stdlib/ndarray-base-strides2offset ^0.0.x
  • @stdlib/ndarray-base-strides2order ^0.0.x
  • @stdlib/ndarray-ctor ^0.0.x
  • @stdlib/string-format ^0.0.x
  • @stdlib/types ^0.0.x
  • @stdlib/utils-flatten-array ^0.0.x
.github/workflows/benchmark.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/cancel.yml actions
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/close_pull_requests.yml actions
  • superbrothers/close-pull-request v3 composite
.github/workflows/examples.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/npm_downloads.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • actions/upload-artifact v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/productionize.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • stdlib-js/bundle-action main composite
  • stdlib-js/transform-errors-action main composite
.github/workflows/publish.yml actions
  • JS-DevTools/npm-publish v1 composite
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • styfle/cancel-workflow-action 0.11.0 composite
.github/workflows/test.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
.github/workflows/test_bundles.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • denoland/setup-deno v1 composite
.github/workflows/test_coverage.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • codecov/codecov-action v3 composite
  • distributhor/workflow-webhook v3 composite
.github/workflows/test_install.yml actions
  • act10ns/slack v1 composite
  • actions/checkout v3 composite
  • actions/setup-node v3 composite