js-num
Version:
It provides equivalent of Numpy in JavaScript.Optimized for generics.js
62 lines (49 loc) • 1.72 kB
JavaScript
var nj = require('./NumpyJS.js');
var a = [
[],
[],
[]
];
var b = [
[],
[],
[]
];
var c = [
[
[],
[],
[]
],
[
[],
[],
[]
]
];
var d = [[[[ 8.33390083, 60.98443236, 82.87877161],
[ 52.54024261, 15.43516277, 43.08813459],
[ 89.43839666, 47.81194975, 59.74936355]],
[[ 51.35553267, 55.52608544, 36.40171026],
[ 33.75042574, 96.4145811 , 88.62963709],
[ 83.15064924, 93.02738429, 30.76654763]]],
[[[ 59.42430445, 60.59745839, 46.22135815],
[ 74.23064867, 50.31342897, 92.88685077],
[ 5.77663918, 14.89315154, 11.56309618]],
[[ 28.54283808, 58.36207678, 54.98849069],
[ 96.90018582, 89.53785394, 59.86437077],
[ 71.28812584, 16.81349852, 50.28981183]]]];
/**
* For mean if the axis is zero then it takes the first element of the first
* row and adds with the next element of the second row example.
* in case of matrix d it adds 0.28566023,64.12966 and divides it by 2.
* so to implement it u take d[0], d[1], d[2]... flatten it
* then add the corresponding elements of the each flattened data.
*/
/**
* For mean if the axis value is same as the last value of the dimension then
* u should add row wise mean in case of matrix d this row
* [ 0.28566023, 11.13529993, 99.25997188] gets summed and it becomes
* the first value of the ans and so on.
*/
console.log(nj.mean(b,1));