JavaScript 多维数组库:Vectorious
dwd4
10年前
Vectorious 是一个 JavaScript 库用来操作 N 维数组和向量。支持 Node.js 和浏览器。
示例代码:
var vectorious = require('vectorious'); var vector, matrix; vector = new vectorious.Vector(); // { values: [], length: 0 } matrix = new vectorious.Matrix(); // { rows: [] } vector = new vectorious.Vector().zeros(5); // { values: [0, 0, 0, 0, 0], length: 5 } vector = new vectorious.Vector(1, 2, 3, 4, 5); // { values: [1, 2, 3, 4, 5], length: 5 } matrix = new vectorious.Matrix(vector); // { rows: [ { values: [1, 2, 3, 4, 5], length: 5 } ] } matrix = new vectorious.Matrix().zeros(2, 2); /* { rows: [ { values: [0, 0], length: 2 }, { values: [0, 0], length: 2 } ] } */ var input = [ [1, 2], [3, 4] ]; matrix = new vectorious.Matrix(input); /* { rows: [ { values: [1, 2], length: 2 }, { values: [3, 4], length: 2 } ] } */