numjs icon indicating copy to clipboard operation
numjs copied to clipboard

mean/sum/min/max/std on axis

Open JoostvDoorn opened this issue 6 years ago • 3 comments

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)

JoostvDoorn avatar Sep 06 '18 06:09 JoostvDoorn

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

nicolaspanel avatar Feb 08 '19 08:02 nicolaspanel

@nicolaspanel Can I work on this?

christianbender avatar Feb 28 '19 17:02 christianbender

@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].

christianbender avatar Mar 05 '19 18:03 christianbender