Skip to content

Mean ​

The arithmetic average of the elements of the collection.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageMean!
Mean(collection)the arithmetic average of the elements.
SageMathmean(collection)Juliaenumeratio_mean(collection)
Mean(matrix)the column-wise mean, one value per column.
SageMathmean(matrix)Juliaenumeratio_mean(matrix)
Typed signatures
TypePackageApplies
((collection<nothing | number> | distribution | number)+) -> numbercompute-enginealways
((collection<nothing | number> | distribution | list<list<any>> | number)*) -> list | numbercombinatoricsreplaces compute-enginealways
((collection<nothing | number> | distribution | list<list<any>> | number)*) -> list | numberstatisticsreplaces combinatoricsalways

Domain: Collections

Details
  • Mean(c)=∑cLength(c)Mean(c) = \dfrac{\sum c}{Length(c)}. See Length.
  • Sensitive to outliers — a single extreme value can drag the mean far from the bulk of the data. See Median for a more robust alternative.
  • Given a matrix (a list of equal-length rows), computes the mean of each column.
  • See Mode for the most frequent value rather than the average.

Examples

Basic #
live ↗
Inmean([1,2,3,4])\mathrm{mean}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack)Out52\frac{5}{2}
live ↗
Inmean([2,4,4,4,5,5,7,9])\mathrm{mean}(\bigl\lbrack2, 4, 4, 4, 5, 5, 7, 9\bigr\rbrack)Out55
live ↗
Inmean([1.21,3.4,2.15,4,1.55])\mathrm{mean}(\bigl\lbrack1.21, 3.4, 2.15, 4, 1.55\bigr\rbrack)Out2.4622.462
Scope #

Given a matrix, Mean is column-wise

live ↗
Inmean([[1,10],[2,20],[3,30]])\mathrm{mean}(\bigl\lbrack\bigl\lbrack1, 10\bigr\rbrack, \bigl\lbrack2, 20\bigr\rbrack, \bigl\lbrack3, 30\bigr\rbrack\bigr\rbrack)Out[2,20]\bigl\lbrack2, 20\bigr\rbrack

Exact rationals give an exact mean

live ↗
Inmean([12,13,16])\mathrm{mean}(\bigl\lbrack\frac{1}{2}, \frac{1}{3}, \frac{1}{6}\bigr\rbrack)Out13\frac{1}{3}

Symbolic data gives an exact symbolic mean: a+b+c+d4\frac{a+b+c+d}{4}

live ↗
Inmean([a,b,c,d])\mathrm{mean}(\bigl\lbrack a, b, c, d\bigr\rbrack)Outa+b+c+d4\frac{a+b+c+d}{4}

Exact constants give an exact mean 2+e+π3\frac{2+e+\pi}{3}, not a numeric approximation

live ↗
Inmean([π,e,2])\mathrm{mean}(\bigl\lbrack π, e, 2\bigr\rbrack)Out2+e+π3\frac{2+e+π}{3}

Of a matrix of symbols, the exact mean of each column

live ↗
Inmean([[a,u],[b,v],[c,w]])\mathrm{mean}(\bigl\lbrack\bigl\lbrack a, u\bigr\rbrack, \bigl\lbrack b, v\bigr\rbrack, \bigl\lbrack c, w\bigr\rbrack\bigr\rbrack)Out[a+b+c3,u+v+w3]\bigl\lbrack\frac{a+b+c}{3}, \frac{u+v+w}{3}\bigr\rbrack

The mean of a lazy Range, exactly

live ↗
Inmean(1..100)\mathrm{mean}(1..100)Out1012\frac{101}{2}

The mean of a 30-digit numeric list is a float

live ↗
Inmean(N([1,2,3,4],30))\mathrm{mean}(N(\bigl\lbrack1, 2, 3, 4\bigr\rbrack, 30))Out2.52.5

Stays symbolic for an unknown data list

live ↗
InN(mean(ts))N(\mathrm{mean}(\mathrm{ts}))Outmean(ts)\mathrm{mean}(\mathrm{ts})

The mean of the binomial distribution is npnp

live ↗
Inmean(BinomialDistribution⁡(n,p))\mathrm{mean}(\operatorname{BinomialDistribution}(n, p))Outnpnp

For a custom density, the integral is not evaluated and the mean stays symbolic

live ↗
Inmean(ProbabilityDistribution(2π((x−2)4+1),[x,−∞,∞]))\mathrm{mean}(\mathrm{ProbabilityDistribution}(\frac{\sqrt{2}}{π((x-2)^4+1)}, \bigl\lbrack x, -∞, ∞\bigr\rbrack))Outmean(ProbabilityDistribution(2π(x−2)4+π,[x,−∞,∞]))\mathrm{mean}(\mathrm{ProbabilityDistribution}(\frac{\sqrt{2}}{π(x-2)^4+π}, \bigl\lbrack x, -∞, ∞\bigr\rbrack))
Properties #

Mean is total divided by count: Mean(c)=∑cLength(c)Mean(c) = \dfrac{\sum c}{Length(c)}. See Length

live ↗
Inmean([1,2,3,4])=1+2+3+4Length([1,2,3,4])\mathrm{mean}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack)=\frac{1+2+3+4}{\mathrm{Length}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack)}OutTrue\mathrm{True}

Numeric evaluation of the mean of eight values

live ↗
InN(mean([1,2,3,4,4,3,1,1]))N(\mathrm{mean}(\bigl\lbrack1, 2, 3, 4, 4, 3, 1, 1\bigr\rbrack))Out2.3752.375

Elementwise functions apply before averaging

live ↗
Inmean(ln⁡([a,b,c,d]))\mathrm{mean}(\ln(\bigl\lbrack a, b, c, d\bigr\rbrack))Out14(ln⁡(a)+ln⁡(b)+ln⁡(c)+ln⁡(d))\frac{1}{4}(\ln(a)+\ln(b)+\ln(c)+\ln(d))

Central moments expand into the centred deviations

live ↗
Inmean(([a,b,c]−mean([a,b,c]))n)\mathrm{mean}((\bigl\lbrack a, b, c\bigr\rbrack-\mathrm{mean}(\bigl\lbrack a, b, c\bigr\rbrack))^{n})Out13((−a3−b3+2c3)n+(−a3+2b3−c3)n+(2a3−b3−c3)n)\frac{1}{3}((-\frac{a}{3}-\frac{b}{3}+\frac{2c}{3})^{n}+(-\frac{a}{3}+\frac{2b}{3}-\frac{c}{3})^{n}+(\frac{2a}{3}-\frac{b}{3}-\frac{c}{3})^{n})

The mean of 1..101..10 is 11/211/2

live ↗
Inmean(1..10)\mathrm{mean}(1..10)Out112\frac{11}{2}
Possible issues #

A single outlier drags the mean far from the rest of the data, here to −383≈−12.67-\frac{38}{3} \approx -12.67. See Median for a more robust alternative

live ↗
Inmean([−100,1,1,1,1,20])\mathrm{mean}(\bigl\lbrack-100, 1, 1, 1, 1, 20\bigr\rbrack)Out−383-\frac{38}{3}

The mean of no data is NaNNaN

live ↗
Inmean([])\mathrm{mean}(\bigl\lbrack\bigr\rbrack)OutNaN⁡\operatorname{NaN}

An outlier of −100-100 drags the mean far below the typical value

live ↗
InN(mean([−100,1,1,1,1,20]))N(\mathrm{mean}(\bigl\lbrack-100, 1, 1, 1, 1, 20\bigr\rbrack))Out−12.666 666 666 666 666 666 7-12.666\,666\,666\,666\,666\,666\,7
About
Examples21
Checked againstWolfram Language 20 agree1 differSageMath 13 agree4 errorOscar 9 agreeJulia 10 agree1 error
CrosswalkWolfram LanguageSageMathJulia

Implementation

mappedoscarpackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts

See also: Median, Mode