Questions tagged [median]

The median is the 'middle' value from a set of values. If the number of values is an even number, the median is the mean of the 'middle' values.

The median is generally used in programming in the sense of the term that comes from statistics. In simple terms it means the number that has half the values above it and half the values below it in the range. It is different than average in that an average can be influenced by extremes on either end of the spectrum. If a few numbers are a lot greater or a lot smaller than the rest, the average will be significantly different from the median. Median can give you a better sense of where the typical middle case is than the average.

The median is also very useful in signal and image processing, in the context of a moving median filter. This filter is usually used to reduce "salt and pepper" type noise, as well as spikes, because each output pixel or element contains the median value of the m-by-n neighborhood around that corresponding pixel in the data.

For a more statistically and technically correct and thorough explanation, see Wikipedia.

In scientific software for statistical computing and graphics, the median of a numeric vector can be found by function median, or quantile with prob = 0.5.

1286 questions
18
votes
6 answers

How to find Median

I have data like this. Ram,500 Sam,400 Test,100 Ram,800 Sam,700 Test,300 Ram,900 Sam,800 Test,400 What is the shortest way to fine the "median" from above data. My result should be something like... Median = 1/2(n+1), where n is the number of data…
user1335606
  • 451
  • 1
  • 5
  • 10
16
votes
4 answers

Help needed with Median If in Excel

I need to return a median of only a certain category on a spread sheet. Example Below Airline 5 Auto 20 Auto 3 Bike 12 Airline 12 Airline 39 ect. How can I write a formula to only return a median value of the Airline…
Alan
  • 161
  • 1
  • 1
  • 3
15
votes
13 answers

How to find k nearest neighbors to the median of n distinct numbers in O(n) time?

I can use the median of medians selection algorithm to find the median in O(n). Also, I know that after the algorithm is done, all the elements to the left of the median are less that the median and all the elements to the right are greater than the…
Anonymous
  • 3,923
  • 10
  • 29
  • 37
15
votes
4 answers

Computing median in map reduce

Can someone example the computation of median/quantiles in map reduce? My understanding of Datafu's median is that the 'n' mappers sort the data and send the data to "1" reducer which is responsible for sorting all the data from n mappers and…
learner
  • 835
  • 3
  • 14
  • 28
14
votes
8 answers

Add a Median Method to a List

I would like to override the List object in C# in order to add a Median method like Sum or Average. I already found this function: public static decimal GetMedian(int[] array) { int[] tempArray = array; int count = tempArray.Length; …
Aladdin Gallas
  • 671
  • 2
  • 11
  • 34
14
votes
6 answers

Efficient way to get middle (median) of an std::set?

std::set is a sorted tree. It provides begin and end methods so I can get minimum and maximum and lower_bound and upper_bound for binary search. But what if I want to get iterator pointing to the middle element (or one of them if there are even…
Qwertiy
  • 14,618
  • 9
  • 41
  • 96
14
votes
1 answer

Optimal 9-element sorting network that reduces to an optimal median-of-9 network?

I am looking into sorting and median-selection networks for nine elements based exclusively on two-input minimum / maximum operations. Knuth, TAOCP Vol. 3, 2nd ed. states (page 226) that a nine-element sorting network requires at least 25…
njuffa
  • 19,228
  • 3
  • 59
  • 102
14
votes
5 answers

how to calculate mean/median per group in a dataframe in r

I have a dataframe recording how much money a costomer spend in detail like the following: custid, value 1, 1 1, 3 1, 2 1, 5 1, 4 1, 1 2, 1 2, 10 3, 1 3, 2 3, 5 How to calcuate the charicteristics using mean,max,median,std, etc like the…
Daniel Wu
  • 5,285
  • 11
  • 35
  • 80
14
votes
4 answers

Running median of y-values over a range of x

Below is a scatter plot I constructed from two numpy arrays. Scatter Plot Example What I'd like to add to this plot is a running median of y over a range of x. I've photoshoped in an example: Modified Scatter Plot Specifically, I need the median…
ikaros
  • 165
  • 1
  • 7
14
votes
2 answers

Get median from number series using Apache Commons Math

Using Apache Commons Math, how do I get the median from a series of numbers? The Commons Math User Guide says DescriptiveStatistics supports median, yet the JavaDocs for DescriptiveStatistics makes no mention of it. It does mention geometric mean,…
Steve Kuo
  • 58,491
  • 75
  • 189
  • 247
13
votes
4 answers

Conditional median in MS Excel

I'm trying to calculate the conditional median of a chart that looks like this: A | B ------- x | 1 x | 1 x | 3 x | y | 4 z | 5 I'm using MS Excel 2007. I am aware of the AVERAGEIF() statement, but there is no equivalent for Median.…
CoolUserName
  • 3,535
  • 5
  • 21
  • 28
13
votes
2 answers

What's the most efficient way to extract min, max & median from a vector

Given a vector vec{...} what's the best way to extract its minimum, maximum and median assuming T is one of the numeric types? I know of std::nth_element as well as std::minmax_element but they seem to do redundant work if called one after…
user1709708
  • 1,507
  • 2
  • 13
  • 23
13
votes
3 answers

Tensorflow median value

How can I calculate the median value of a list in tensorflow? Like node = tf.median(X) X is the placeholder In numpy, I can directly use np.median to get the median value. How can I use the numpy operation in tensorflow?
Yingchao Xiong
  • 235
  • 3
  • 10
13
votes
3 answers

Standard sorting networks for small values of n

I'm looking for a sorting network implementation of a 5-element sort, but since I couldn't find a good reference on SO, I'd like to ask for sorting networks for all small values of n, at least n=3 through n=6 but higher values would be great too. A…
R.. GitHub STOP HELPING ICE
  • 195,354
  • 31
  • 331
  • 669
13
votes
1 answer

Explanation of the Median of Medians algorithm

The Median of medians approach is very popular in quicksort type partitioning algorithms to yield a fairly good pivot, such that it partitions the array uniformly. Its logic is given in Wikipedia as: The chosen pivot is both less than and greater…
SexyBeast
  • 8,635
  • 25
  • 92
  • 179
1 2
3
85 86