klyn.math.NDArray.mean
method
public mean(axis as Long, keepDims as Boolean = false, ignoreNaN as Boolean = false, where as Boolean[] = null, result as NDArray<Double> = null) as NDArray<Double>
Description

Computes the arithmetic mean along one axis.

Parameters
ParameterDescription
axisAxis to reduce on any rank; negative axes count from the end.
keepDimsRetain reduced dimensions with length one.
resultOptional non-aliased destination of the exact output shape.
whereOptional flat Boolean selection mask.
ignoreNaNSkip NaNs; otherwise preserve this operation's default NaN contract.
Returns

A NDArray<Double> containing axis means.

Throws
  • IndexException if the axis does not exist.
  • ValueException if the array is empty.
  • IndexException for an invalid axis.
  • ValueException for invalid mask/destination or no observations (except sum).
Example
import klyn.math

a = NDArray<Int>([[1, 2], [3, 4]])
print(a.mean(0))  # [2.0, 3.0]
print(a.mean(1))  # [1.5, 3.5]