nicolaspanel / numjs

Like NumPy, in JavaScript
MIT License
2.4k stars 184 forks source link

mean/sum/min/max/std on axis #54

Open JoostvDoorn opened 6 years ago

JoostvDoorn commented 6 years ago

It would be very helpful if numjs supported mean/sum/min/max etc. over a specific axis like numpy.

a = nj.random([2,3]);
nj.mean(a, axis=1)
nicolaspanel commented 5 years ago

I agree it would be nice I have no bandwidth right now but PR are always welcome ;)

christianbender commented 5 years ago

@nicolaspanel Can I work on this?

christianbender commented 5 years ago

@nicolaspanel @JoostvDoorn I build a function meanaxis(arr, axis = 0) for square matrices like [[1, 2], [3, 4]]. Inclusive tests.

/**
 * Calculates the arithmetic mean over a specific axis
 * axis := 0 means x-axis (columns)
 * axis := 1 means y-axis (rows)
 * @param {NdArray} arr 
 * @param {Integer} axis (0 or 1)
 */
function meanaxis(arr, axis = 0)

I changed the function for calculating simple vectors like [1, 2, 3].