Compute the median of the <freq_col>'th column of the values is <data>.

>>> chart_data.median([(10,20), (20,4), (30,5)], 0)
20
>>> chart_data.median([(10,20), (20,4), (30,5)], 1)
5.
960127
def median(data, freq_col=1):
    

    nr_data = _nr_data(data, freq_col)
    median_idx = nr_data / 2
    i = 0
    for d in data:
        i += d[freq_col]
        if i >= median_idx:
            return d
    raise Exception("??? median ???")
1219908
public function median() : ColumnVector
    {
        if ($this->n < 1) {
            throw new RuntimeException('Median is not defined for matrices'
                . ' with less than 1 column.');
        }

        $b = [];

        foreach ($this->a as $row) {
            $mid = intdiv($this->n, 2);

            sort($row);

            if ($this->n % 2 === 1) {
                $median = $row[$mid];
            } else {
                $median = ($row[$mid - 1] + $row[$mid]) / 2.;
            }

            $b[] = $median;
        }

        return ColumnVector::quick($b);
    }
977953
def sumvalues(self, q=0):
        
        if q == 0:
            return self._totalf
        else:
            return -np.partition(-self._freq_list, q)[:q].sum()
233157
def asfreq(self, freq):
        
        frame = self.frame
        if freq == 'B':
            resampled = frame.groupby(frame.index.date).apply(lambda f: f.sum())
            resampled.index = pd.DatetimeIndex([i for i in resampled.index])
            return ProfitAndLossDetails(resampled)
        else:
            resampled = frame.resample(freq, how='sum')
            return ProfitAndLossDetails(resampled)
296751
public static int median(ArrayModifiableDBIDs data, Comparator<? super DBIDRef> comparator) {
    return median(data, comparator, 0, data.size());
  }
957288
private void computeChartSteps() {
        //if special type
        if (chartType == GraphPanelChart.CHART_PERCENTAGE) {
            minYVal = 0;
            maxYVal = 100;
            return;
        }

        //try to find the best range...
        //first, avoid special cases where maxY equal or close to minY
        if (maxYVal - minYVal < 0.1) {
            maxYVal = minYVal + 1;
        }

        //real step
        double step = (maxYVal - minYVal) / gridLinesCount;

        int pow = -1;
        double factor = -1;
        boolean found = false;

        double testStep;

        //find a step close to the real one
        while (!found) {
            pow++;

            for (double f = 0; f < 10; f++) {
                testStep = Math.pow(10, pow) * f;
                if (testStep >= step) {
                    factor = f;
                    found = true;
                    break;
                }
            }
        }

        //first proposal
        double foundStep = Math.pow(10, pow) * factor;

        //we shift to the closest lower minval to align with the step
        minYVal = minYVal - minYVal % foundStep;

        //check if step is still good with minY trimmed. If not, use next factor.
        if (minYVal + foundStep * gridLinesCount < maxYVal) {
            foundStep = Math.pow(10, pow) * (factor + (pow > 0 ? 0.5 : 1));
        }

        //last visual optimization: find the optimal minYVal
        double trim = 10;

        while ((minYVal - minYVal % trim) + foundStep * gridLinesCount >= maxYVal && minYVal > 0) {
            minYVal = minYVal - minYVal % trim;
            trim = trim * 10;
        }

        //final calculation
        maxYVal = minYVal + foundStep * gridLinesCount;
    }
446359
def median(array):
    
    n = len(array)

    if n < 1:
        return 0
    elif n == 1:
        return array[0]

    sorted_vals = sorted(array)
    midpoint = int(n / 2)
    if n % 2 == 1:
        return sorted_vals[midpoint]
    else:
        return (sorted_vals[midpoint - 1] + sorted_vals[midpoint]) / 2.0
616296
def median_grouped(name, num, minimum=0, maximum=0, ref=None):
    '''
    
    '''
    return calc(
        name=name,
        num=num,
        oper='median_grouped',
        minimum=minimum,
        maximum=maximum,
        ref=ref
    )
739847
def fn_median(self, a, axis=None):
        

        return numpy.nanmedian(self._to_ndarray(a), axis=axis)
142363
def numeric_summary
      summary = "\n  median: #{median}" +
                "\n  mean: %0.4f" % mean
      if sd
        summary << "\n  std.dev.: %0.4f" % sd +
                   "\n  std.err.: %0.4f" % se
      end

      if count_values(*Daru::MISSING_VALUES).zero?
        summary << "\n  skew: %0.4f" % skew +
                   "\n  kurtosis: %0.4f" % kurtosis
      end
      summary
    end
169907
public function median(): float
    {
        $a = $this->a;
        $b = $this->b;

        return ($a + $b) / 2;
    }
831925
public static int Median( int[] values ){
        int total = 0, n = values.length;

        // for all values
        for ( int i = 0; i < n; i++ )
        {
            // accumalate total
            total += values[i];
        }

        int halfTotal = total / 2;
        int median = 0, v = 0;

        // find median value
        for ( ; median < n; median++ )
        {
            v += values[median];
            if ( v >= halfTotal )
                break;
        }

        return median;
    }
768336
function median(input) {
                if (!Array.isArray(input)) {
                    throw new Error('input must be an array');
                }

                if (input.length === 0) {
                    throw new Error('input must not be empty');
                }

                return medianQuickselect_min(input.slice());
            }
1298836
def _infer_interval_breaks(coord, axis=0, check_monotonic=False):
    
    coord = np.asarray(coord)

    if check_monotonic and not _is_monotonic(coord, axis=axis):
        raise ValueError("The input coordinate is not sorted in increasing "
                         "order along axis %d. This can lead to unexpected "
                         "results. Consider calling the `sortby` method on "
                         "the input DataArray. To plot data with categorical "
                         "axes, consider using the `heatmap` function from "
                         "the `seaborn` statistical plotting library." % axis)

    deltas = 0.5 * np.diff(coord, axis=axis)
    if deltas.size == 0:
        deltas = np.array(0.0)
    first = np.take(coord, [0], axis=axis) - np.take(deltas, [0], axis=axis)
    last = np.take(coord, [-1], axis=axis) + np.take(deltas, [-1], axis=axis)
    trim_last = tuple(slice(None, -1) if n == axis else slice(None)
                      for n in range(coord.ndim))
    return np.concatenate([first, coord[trim_last] + deltas, last], axis=axis)
649923
def median(lst):
    
    #: http://stackoverflow.com/a/24101534
    sortedLst = sorted(lst)
    lstLen = len(lst)
    index = (lstLen - 1) // 2
    if (lstLen % 2):
        return sortedLst[index]
    else:
        return (sortedLst[index] + sortedLst[index + 1])/2.0
902170
def median(numbers):
    

    # Sort the list and take the middle element.
    n = len(numbers)
    copy = sorted(numbers)
    if n & 1:  # There is an odd number of elements
        return copy[n // 2]
    else:
        return (copy[n // 2 - 1] + copy[n // 2]) / 2.0
357272
def compute_balance_median_ts(self, ts):
        
        balance = [self.compute_balance_median(ts, t) for t in np.arange(0, len(ts) - 1)]
        return balance