Returns the mean of all items in a matrix.
Every cell counts once, whatever its row or column, and the result is the total divided by the number of items. The matrix [[1, 2], [3, 4]] averages to 2.5.
For a row or column on its own, take it with matrix.row() or matrix.col() and use array.avg().
Syntax
matrix.avg(id: matrix<int/float>) -> series float
matrix.avg(id: matrix<int>) -> series int
matrix.avg() -> series float
matrix.avg() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | matrix<int/ | required | The matrix whose items are all averaged together, whatever its shape. |
Returns
series float: The mean of every item as a float.series int: The mean typed as a whole number, to match an integer matrix; a decimal-valued matrix keeps the fraction.series float: The mean of every item in the receiving matrix as a float.series int: The mean of the receiving matrix typed as a whole number.
Example
//@version=6
indicator("matrix.avg: grid mean", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 3.0)
matrix.set(m, 0, 0, 7.0)
plot(matrix.avg(m), "Mean")See also
Runs on Sidechair