Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.05 KB

average.md

File metadata and controls

64 lines (42 loc) · 1.05 KB

average

Compute the weighted arithmetic mean of an array.

API

Numeric.stat.average(values, weights, level)

Averages the values with the supplied weights.

  • Parameters:
    • values: Vector or matrix of input values
    • weights: Weights applied to each value
    • level: Optional axis along which to average
  • Returns: Weighted mean of the values
  • NumPy: Equivalent to np.average.

Examples

Mean of a vector

import Numeric from '@neabyte/numerix'

const value = Numeric.stat.average([1, 2, 3])

console.log(value)
// 2

Weighted mean of a vector

import Numeric from '@neabyte/numerix'

const value = Numeric.stat.average([1, 2, 3], [1, 1, 2])

console.log(value)
// 2.25

Weighted mean with equal weights

import Numeric from '@neabyte/numerix'

const value = Numeric.stat.average([1, 2, 3], [1, 1, 1])

console.log(value)
// 2

Weighted mean favouring the last value

import Numeric from '@neabyte/numerix'

const value = Numeric.stat.average([0, 10], [1, 3])

console.log(value)
// 7.5