- See Also
-
Related Guides
- Descriptive Statistics
- Survival Analysis
- Computation with Structured Datasets
- Probability & Statistics
- Statistical Data Analysis
- Date & Time
- Math & Counting Operations on Lists
- Numerical Data
- Discrete & Integer Data
- Scientific Data Analysis
- Robust Descriptive Statistics
- Time Series Processing
- Image Processing & Analysis
- Spatial Statistics
- Probability & Statistics with Quantities
- Tabular Transformation
- Tabular Modeling
- Event Series Processing
- Audio Processing
- Tech Notes
-
- See Also
-
Related Guides
- Descriptive Statistics
- Survival Analysis
- Computation with Structured Datasets
- Probability & Statistics
- Statistical Data Analysis
- Date & Time
- Math & Counting Operations on Lists
- Numerical Data
- Discrete & Integer Data
- Scientific Data Analysis
- Robust Descriptive Statistics
- Time Series Processing
- Image Processing & Analysis
- Spatial Statistics
- Probability & Statistics with Quantities
- Tabular Transformation
- Tabular Modeling
- Event Series Processing
- Audio Processing
- Tech Notes
Median
Details
- Median is a robust location estimator, which means it is not very sensitive to outliers.
- For VectorQ data
, the median can be thought of as the "middle value". - Formally, when data is sorted as
, the median is given by center element
if
is odd and the mean of the two center elements
if
is even. - Median[data] is equivalent to Quantile[data,1/2,{{1/2,0},{0,1}}].
- For MatrixQ data, the median is computed for each column vector with Median[{{x1,y1,…},{x2,y2,…},…}] equivalent to {Median[{x1,x2,…}],Median[{y1,y2,…}],…}. »
- For ArrayQ data, median is equivalent to ArrayReduce[Median,data,1]. »
- The data can have the following additional forms and interpretations:
-
Association the values (the keys are ignored) » SparseArray as an array, equivalent to Normal[data] » QuantityArray quantities as an array » WeightedData based on the underlying EmpiricalDistribution » EventData based on the underlying SurvivalDistribution » TimeSeries, TemporalData, … vector or array of values (the time stamps ignored) » Image,Image3D RGB channels values or grayscale intensity value » Audio amplitude values of all channels » DateObject, TimeObject list of dates or list of times » - Median[dist] is the minimum of the set of number(s) m such that Probability[x≤m,xdist]≥1/2 and Probability[x≥m,xdist]≥1/2. »
- For a continuous distribution dist, the median can be defined using the cumulative distribution function:
. - Median[dist] is equivalent to Quantile[dist,1/2].
- For a random process proc, the median function
can be computed for slice distribution at time t, SliceDistribution[proc,t], as Median[SliceDistribution[proc,t]]. »
Examples
open all close allBasic Examples (4)
Find the middle value in the list:
Median[{1, 2, 3, 4, 5, 6, 7}]Average the two middle values:
Median[{1, 2, 3, 4, 5, 6, 7, 8}]dates = Table[DateObject[{2024, k}], {k, 1, 12}]Median[dates]Median of a parametric distribution:
Median[ExponentialDistribution[λ]]Scope (24)
Basic Uses (8)
Exact input yields exact output:
Median[{1, 2, 3, 4}]Median[{π, E, 2}]Approximate input yields approximate output:
Median[{1., 2., 3., 4.}]Median[N[{1, 2, 3, 4}, 30]]Find the median of WeightedData:
Median[WeightedData[{1, 2, 3}, {3, 7, 4}]]data = {8, 3, 5, 4, 9, 0, 4, 2, 2, 3};
weights = {0.15, 0.09, 0.12, 0.10, 0.16, 0., 0.11, 0.08, 0.08, 0.09};Median[WeightedData[data, weights]]Find the median of EventData:
e = {1.0, 2.1, 3.2, 4.5, 5.7};
ci = {0, 0, 0, 1, 0};Median[EventData[e, ci]]Find the median of TemporalData:
s1 = {2, 1, 6, 5, 7, 4};
s2 = {4, 7, 5, 6, 1, 2};
t = {1, 2, 5, 10, 12, 15};td = TemporalData[{s1, s2}, {t}];Median[td[10]]Find the median of a TimeSeries:
v = {3, 8, 4, 11, 9, 2};
t = {1, 3, 5, 7, 8, 10};
ts = TimeSeries[v, {t}];Median[ts]The median depends only on the values:
Median[ts["Values"]]Find a three-element moving median:
MovingMap[Median, {2.5, 1.2, 6.9, 5.8, 7.1, 4.8}, Quantity[3, "Events"]]Find the median of data involving quantities:
data = Quantity[RandomReal[1, 6], "Meters"]Median[data]Array Data (5)
Median for a matrix gives columnwise medians:
Median[{{1, 11, 3}, {4, 6, 7}}]Median for a tensor gives columnwise medians at the first level:
Median[{{{3, 7}, {2, 1}}, {{5, 19}, {12, 4}}}]Median[RandomReal[1, 10 ^ 7]]Median[RandomReal[1, {10 ^ 6, 5}]]When the input is an Association, Median works on its values:
mat = RandomReal[1, {3, 2}];assoc = AssociationThread[Range[3], mat]
Median[assoc]SparseArray data can be used just like dense arrays:
Median[SparseArray[{{1} -> 1, {100} -> 1}]]Median[SparseArray[{{1, 1} -> 1, {2, 2} -> 2, {3, 3} -> 3, {1, 3} -> 4}]]Find median of a QuantityArray:
data = QuantityArray[RandomReal[1, 6], "Pounds"]Median[data]Image and Audio Data (2)
Channel-wise median value of an RGB image:
Median[[image]]RGBColor[%]Median intensity value of a grayscale image:
Median[[image]]Median amplitude of all amplitude values of all channels:
a = ExampleData[{"Audio", "Bee"}]Median[a]Date and Time (5)
dates = WolframLanguageData[All, "DateIntroduced"];DateHistogram[dates]Median[dates]Compute the weighted median of dates:
dates = RandomDate[4]weights = {1, 1, 1, 3};Median[WeightedData[dates, weights]]Compute the median of DateObject objects given in different calendars:
dates = {DateObject[{6024, 1, 15}, CalendarType -> "Jewish"], DateObject[{2024, 2, 29}, CalendarType -> "Julian"], DateObject[{1524, 1, 1}, CalendarType -> "Islamic"]}Median[dates]The given dates in the "Gregorian" calendar:
TimelinePlot[dates, ImageSize -> Medium]Since no calendar type is dominating in the data, reordering will change the calendar type of the result:
RotateLeft[dates]Median[%]The median itself is the same:
% == Median[dates]Compute the median of TimeObject objects:
times = RandomTime[3]Median[times]Compute the median of times with different time zone specifications:
times = {TimeObject[{12}, TimeZone -> -3], TimeObject[{12}, TimeZone -> 2], TimeObject[{12}, TimeZone -> "Asia/Tokyo"]}Median[times]DateValue[%, "TimeZone"]Since no time zone is dominating in the data, reordering will change the time zone of the result:
RotateRight[times]Median[%]The median itself is the same:
% == Median[times]Distributions and Processes (4)
Find the median for a parametric distribution:
Median[NormalDistribution[μ, σ]]Median for a derived distribution:
Median[TransformedDistribution[x^2, xNormalDistribution[]]]Median[ProbabilityDistribution[8.x ^ 7 / 255, {x, 1, 2}]]data = RandomVariate[NormalDistribution[], 10 ^ 3];Median[HistogramDistribution[data]]Median for distributions with quantities:
Median[GammaDistribution[1.7, Quantity[7, "Meters"]]]Median[EmpiricalDistribution[QuantityArray[RandomChoice[{0, 5}, 1000], "Volts"]]]Median function for a time slice of a random process:
Median[PoissonProcess[3][4]]Plot[Median[PoissonProcess[3][t]], {t, 0, 10}]Applications (7)
The median represents the center of a distribution:
dists = {NormalDistribution[3, 1], WeibullDistribution[2, 2]};Table[With[{m = Median[𝒟]}, Plot[PDF[𝒟, x], {x, 0, 6}, Filling -> Axis, Epilog -> {Directive[Red, Dotted, Thick], Line[{{m, 0}, {m, PDF[𝒟, m]}}]}]], {𝒟, dists}]The median for a distribution without a single mode:
dists = {ExponentialDistribution[1], MixtureDistribution[{2, 1}, {NormalDistribution[2, 0.5], NormalDistribution[5, 1 / 2]}]};Table[With[{m = Median[𝒟]}, Plot[PDF[𝒟, x], {x, 0, 6}, Filling -> Axis, Epilog -> {Directive[Red, Dotted, Thick], Line[{{m, 0}, {m, PDF[𝒟, m]}}]}]], {𝒟, dists}]Find the median length, in miles, for 141 major rivers in North America:
data = ExampleData[{"Statistics", "RiverLengths"}];Length[data]m = Median[data]Plot a Histogram for the data:
highlightbar[{{x0_, x1_}, {y0_, y1_}}, data_, meta___] := {If[x0 ≤ First[meta] < x1, Red, {}], Rectangle[{x0, y0}, {x1, y1}]}Histogram[data -> m, ChartElementFunction -> highlightbar]Probability that the length exceeds 90% of the median:
NProbability[x > 0.9m, xdata]Smooth an irregularly spaced time series using a moving median:
data = TemporalData[TimeSeries, {{{26.27, 24.26, 23.94, 23.08, 24.17, 23.99, 23.27, 24.09, 22.78, 21.51,
21.68, 21.74, 20.97, 18.74, 18.27, 17.52, 17.52, 17.73, 17.81, 18.24, 18.02, 17.74, 17.43,
16.44, 16.34, 16.91, 17.44, 16.82, 17.44, 17.18, ... 200, 3628281600,
3628368000, 3628540800, 3628800000, 3628886400, 3628972800, 3629145600}}}, 1,
{"Continuous", 1}, {"Discrete", 1}, 1, {ValueDimensions -> 1,
ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, True, 10.1];med = MovingMap[Median, data, {Quantity[90, "Day"]}];Show[DateListPlot[data, PlotStyle -> GrayLevel[.7]], DateListPlot[med, Joined -> True, PlotStyle -> Thick]]Obtain a robust estimate of location when outliers are present:
Median[{1, 5, 2, 6, 10, 10 ^ 5, 5, 4}]Extreme values have a large influence on the Mean:
Mean[{1, 5, 2, 6, 10, 10 ^ 5, 5, 4}]//NCompute medians for slices of a collection of paths of a random process:
data = RandomFunction[WienerProcess[], {0, 1, .01}, 10 ^ 3];times = Range[0, 1, .1];med = Map[{#, Median[data[#]]}&, times];Plot medians over these paths:
Show[ListPlot[data], ListLinePlot[med, PlotStyle -> Green]]Find the median height for the children in a class:
heights = Quantity[{134, 143, 131, 140, 145, 136, 131, 136, 143, 136, 133, 145, 147,
150, 150, 146, 137, 143, 132, 142, 145, 136, 144, 135, 141}, "Centimeters"];ListPlot[heights, Filling -> Axis, AxesLabel -> Automatic]m = Median[heights]ListPlot[{heights, {{0, m}, {25, m}}}, Joined -> {False, True}, Filling -> Axis, AxesLabel -> Automatic]Properties & Relations (7)
Median is equivalent to a parametrized Quantile:
data = RandomReal[20, 50];Quantile[data, 1 / 2, {{1 / 2, 0}, {0, 1}}]Median[data]For nearly symmetric samples, Median and Mean are nearly the same:
Mean[{1, 2, 3, 4, 4, 3, 1, 1}]//NMedian[{1, 2, 3, 4, 4, 3, 1, 1}]//NFor univariate data, Median coincides with SpatialMedian:
Median[{1, 2, 3, 4, 4, 3, 1, 1}]SpatialMedian[{1, 2, 3, 4, 4, 3, 1, 1}]The Median of absolute deviations from the Median is MedianDeviation:
data = RandomReal[10, 10];MedianDeviation[data]Median[Abs[data - Median[data]]]MovingMedian is a sequence of medians:
MovingMedian[{1, 5, 2, 3, 10, 6}, 3]Table[Median[Take[{1, 5, 2, 3, 10, 6}, {i, i + 2}]], {i, 4}]For any distribution, there is InverseCDF[dist,1/2]=Median[dist]:
Subscript[𝒟, 1] = NormalDistribution[];
Subscript[𝒟, 2] = GeometricDistribution[1 / 12];InverseCDF[Subscript[𝒟, 1], 1 / 2] == Median[Subscript[𝒟, 1]]InverseCDF[Subscript[𝒟, 2], 1 / 2] == Median[Subscript[𝒟, 2]]Similarly for InverseSurvivalFunction:
InverseSurvivalFunction[Subscript[𝒟, 1], 1 / 2] == Median[Subscript[𝒟, 1]]InverseSurvivalFunction[Subscript[𝒟, 2], 1 / 2] == Median[Subscript[𝒟, 2]]For a continuous distribution, there is CDF[dist,Median[dist]]=1/2:
𝒩 = NormalDistribution[];CDF[𝒩, Median[𝒩]]Similarly for SurvivalFunction:
SurvivalFunction[𝒩, Median[𝒩]]For discrete distributions, the identity does not hold:
𝒢 = GeometricDistribution[1 / 12];CDF[𝒢, Median[𝒢]]N[%]Possible Issues (2)
Median requires numeric values:
Median[{a, b, c}]Median of data computed via Quantile does not always agree with Median:
data = RandomReal[10, 20];Quantile[data, 1 / 2]Median[data]%% - %Specify linear interpolation parameters in Quantile:
Quantile[data, 1 / 2, {{1 / 2, 0}, {0, 1}}]%%% - %Neat Examples (1)
The distribution of Median estimates for 20, 100, and 300 samples:
Median[ExponentialDistribution[0.9]]SmoothHistogram[Table[Median[RandomVariate[ExponentialDistribution[0.9], {s, 1000}]], {s, {20, 100, 300}}], Filling -> Axis, PlotLegends -> {20, 100, 300}, PlotRange -> {{0, 2}, Automatic}]Tech Notes
Related Guides
-
▪
- Descriptive Statistics ▪
- Survival Analysis ▪
- Computation with Structured Datasets ▪
- Probability & Statistics ▪
- Statistical Data Analysis ▪
- Date & Time ▪
- Math & Counting Operations on Lists ▪
- Numerical Data ▪
- Discrete & Integer Data ▪
- Scientific Data Analysis ▪
- Robust Descriptive Statistics ▪
- Time Series Processing ▪
- Image Processing & Analysis ▪
- Spatial Statistics ▪
- Probability & Statistics with Quantities ▪
- Tabular Transformation ▪
- Tabular Modeling ▪
- Event Series Processing ▪
- Audio Processing
History
Introduced in 2003 (5.0) | Updated in 2008 (7.0) ▪ 2016 (11.0) ▪ 2023 (13.3) ▪ 2024 (14.1)
Text
Wolfram Research (2003), Median, Wolfram Language function, https://reference.wolfram.com/language/ref/Median.html (updated 2024).
CMS
Wolfram Language. 2003. "Median." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/Median.html.
APA
Wolfram Language. (2003). Median. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Median.html
BibTeX
@misc{reference.wolfram_2026_median, author="Wolfram Research", title="{Median}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/Median.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_median, organization={Wolfram Research}, title={Median}, year={2024}, url={https://reference.wolfram.com/language/ref/Median.html}, note=[Accessed: 12-June-2026]}