OpenMusic Reference
om-mean
om-mean
(arithmetic module) -- returns the arithmetic mean of numbers in a list
Syntax
om-mean self &optional weights
Inputs
name | data type(s) | comments |
---|---|---|
self | a list | |
weights | a list | an optional list of numbers to ponderate the elements of self |
Output
output | data type(s) | comments |
---|---|---|
first | a number | returns the arithmetic mean of the numbers in the list |
Description
This function returns the arithmetic mean of the numbers in self , which may be of mixed type. This arithmetic mean is obtained by adding all of the elements in the list together and dividing by the number of elements.
The second input, weights , is a list of values used to ponderate (to weight) the values of the first input. If this list is shorter than self the extra elements in self are not weighted. Weighting an element with a value n causes the mean to be calculated as if that element appeared n times.
Examples
Taking a weighted average of a list
Normally, taking the average of (1 2 3 4 5) will return 3, since 1+2+3+4+5 is 15, divided by 5 gives three. This example shows a weighting of the list towards the higher numbers- 3,4,5 are assigned a weight of 1.5 instead of 1. The answer in this case is 3.230769230769231.
Prev | Home | Next |
---|---|---|
om-max | Up | om-min |