median (Descriptive Statistics)


Import

#include <archr/stats/median.h>
#include <archr/stats/median.hpp>
import archr.stats
atomsLoads('archr')

Synopsis

 double archr_stats_median_f32(float *first, size_t nbelem);
(1)
 double archr_stats_median_f64(double *first, size_t nbelem);
(2)
 double archr_stats_median_i8(int8_t *first, size_t nbelem);
(3)
 double archr_stats_median_i16(int16_t *first, size_t nbelem);
(4)
 double archr_stats_median_i32(int32_t *first, size_t nbelem);
(5)
 double archr_stats_median_i64(int64_t *first, size_t nbelem);
(6)
 double archr_stats_median_u8(uint8_t *first, size_t nbelem);
(7)
 double archr_stats_median_u16(uint16_t *first, size_t nbelem);
(8)
 double archr_stats_median_u32(uint32_t *first, size_t nbelem);
(9)
 double archr_stats_median_u64(uint64_t *first, size_t nbelem);
(10)
 double median(float *first, size_t nbelem);
(1)
 double median(double *first, size_t nbelem);
(2)
 double median(int8_t *first, size_t nbelem);
(3)
 double median(int16_t *first, size_t nbelem);
(4)
 double median(int32_t *first, size_t nbelem);
(5)
 double median(int64_t *first, size_t nbelem);
(6)
 double median(uint8_t *first, size_t nbelem);
(7)
 double median(uint16_t *first, size_t nbelem);
(8)
 double median(uint32_t *first, size_t nbelem);
(9)
 double median(uint64_t *first, size_t nbelem);
(10)
 double median(float *first, float *last);
(11)
 double median(double *first, double *last);
(12)
 double median(int8_t *first, int8_t *last);
(13)
 double median(int16_t *first, int16_t *last);
(14)
 double median(int32_t *first, int32_t *last);
(15)
 double median(int64_t *first, int64_t *last);
(16)
 double median(uint8_t *first, uint8_t *last);
(17)
 double median(uint16_t *first, uint16_t *last);
(18)
 double median(uint32_t *first, uint32_t *last);
(19)
 double median(uint64_t *first, uint64_t *last);
(20)
template <typename Range> double median(Range& data);
(21)
subroutine archr_stats_median_f32(real(8) :: r, real(4), dimension(*) :: first, integer(4) :: nbelem)
(1)
subroutine archr_stats_median_f64(real(8) :: r, real(8), dimension(*) :: first, integer(4) :: nbelem)
(2)
subroutine archr_stats_median_i8(real(8) :: r, integer(1), dimension(*) :: first, integer(4) :: nbelem)
(3)
subroutine archr_stats_median_i16(real(8) :: r, integer(2), dimension(*) :: first, integer(4) :: nbelem)
(4)
subroutine archr_stats_median_i32(real(8) :: r, integer(4), dimension(*) :: first, integer(4) :: nbelem)
(5)
subroutine archr_stats_median_i64(real(8) :: r, integer(8), dimension(*) :: first, integer(4) :: nbelem)
(6)
subroutine archr_stats_median_u8(real(8) :: r, integer(1), dimension(*) :: first, integer(4) :: nbelem)
(7)
subroutine archr_stats_median_u16(real(8) :: r, integer(2), dimension(*) :: first, integer(4) :: nbelem)
(8)
subroutine archr_stats_median_u32(real(8) :: r, integer(4), dimension(*) :: first, integer(4) :: nbelem)
(9)
subroutine archr_stats_median_u64(real(8) :: r, integer(8), dimension(*) :: first, integer(4) :: nbelem)
(10)
def median(first):
    return r
(1)
function r = archr_stats_median(first)
(1)

Description

This function computes the median of the elements stored in:

Note that this computation may alter the ordering of the original sequence.

Parameters

first

the beginning of the range of elements to process.

last

the end of the range of elements to process.

nbelem

the number of elements to process.

Return value

The median of the elements in the given range defined as the value that split the sorted range in two parts of equal size.

Example

#include <archr/stats/median.h>
#include <stdio.h>

int main()
{
  int v[] = {3,9,1,2,0,10,5,7};

  printf("median(3,9,1,2,0,10,5,7) = %f\n", archr_stats_median_i32(&v[0],8));

  return 0;
}

Possible Output

median(3,9,1,2,0,10,5,7) = 3.500000
median(3,9,1,2,0)        = 2.000000
#include <archr/stats/median.hpp>
#include <iostream>
#include <vector>

int main()
{
 std::vector<std::int32_t> v{3,9,1,2,0,10,5,7};

 std::cout << "median(3,9,1,2,0,10,5,7) = " << archr::stats::median(v) << "\n";
 std::cout << "median(3,9,1,2,0)        = " << archr::stats::median(v.data(), 5) << "\n";
 std::cout << "median(3,9,1,2)          = " << archr::stats::median(v.data(), v.data() + 4) << "\n";

  return 0;
}

Possible Output

median(3,9,1,2,0,10,5,7) = 3.5
median(3,9,1,2,0)        = 2
median(3,9,1,2)          = 1.5

Possible Output