0.1.0 • Published 8 years ago

ts-vector v0.1.0

Weekly downloads
18
License
MIT
Repository
github
Last release
8 years ago

ts-vector

ts-vector provides a Vector class that extends the JavaScript/TypeScript array with the most commonly used mathematical and statistical functions.

This library uses EcmaScript 6 array inheritance, so it's not going to work in old browsers! Node.js 5.0 and the latest Chrome already support most of the Array inheritance features.

Install it from NPM: npm install ts-vector , or use a bundled .js file: ts-vector.js

Check the API Reference

Examples

var v = new Vector(100).fillBy(() => Math.random());
var {x,y,dx} = v.histogram({ bins: 10 }); 
var mode = x[y.argmax()];
console.log('Most values between:', mode, mode + dx);
var y_cum = y.cumsum();
console.log('Cumulative distribution:', x, y_cum);

var lessCount = v.lessThan(0.5).sum();
console.log('Smaller than 0.5:', lessCount/v.length);

// vector operations:

var v = Vector.from([0, 3, 2, 12, 3]);
var size = v.magnitude();
var result = v.add(1).subtract([1, 3, -2, 2, 7]).dot([5, 0, 1, -3, 4]);

Licensing

MIT License