Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scijs/ndarray

📈 Multidimensional arrays for JavaScript
https://github.com/scijs/ndarray

Last synced: 5 days ago
JSON representation

📈 Multidimensional arrays for JavaScript

Awesome Lists containing this project

README

        

ndarray
=======
Modular multidimensional arrays for JavaScript.

[![browser support](https://ci.testling.com/mikolalysenko/ndarray.png)
](https://ci.testling.com/mikolalysenko/ndarray)

[![build status](https://secure.travis-ci.org/scijs/ndarray.png)](http://travis-ci.org/scijs/ndarray)

[![stable](https://rawgithub.com/hughsk/stability-badges/master/dist/frozen.svg)](http://github.com/hughsk/stability-badges)

##### Browse a number of ndarray-compatible modules in the [scijs documentation](http://scijs.net/packages)
##### Coming from MATLAB or numpy? See: [scijs/ndarray for MATLAB users](https://github.com/scijs/scijs-ndarray-for-matlab-users)
##### [Big list of ndarray modules](https://github.com/scijs/ndarray/wiki/ndarray-module-list#core-module)

Introduction
============
`ndarrays` provide higher dimensional views of 1D arrays. For example, here is how you can turn a length 4 typed array into an nd-array:

```javascript
var mat = ndarray(new Float64Array([1, 0, 0, 1]), [2,2])

//Now:
//
// mat = 1 0
// 0 1
//
```

Once you have an nd-array you can access elements using `.set` and `.get`. For example, here is an implementation of [Conway's game of life](http://en.wikipedia.org/wiki/Conway's_Game_of_Life) using ndarrays:

```javascript
function stepLife(next_state, cur_state) {

//Get array shape
var nx = cur_state.shape[0],
ny = cur_state.shape[1]

//Loop over all cells
for(var i=1; i