NumDart

Statistics

Mean, median, mode, variance and standard deviation of a sample.

Like numpy.mean, numpy.median, scipy.stats.mode

Descriptive statisticsMean, median, mode, variance and standard deviation of a sample.
import 'package:scidart/numdart.dart';

void main() {
  var a = Array([2, 4, 4, 4, 5, 5, 7, 9]);

  print('mean: ${mean(a)}');
  print('median: ${median(a)}');
  print('mode: ${mode(a)}');
  print('multimode: ${multimode(Array([1, 1, 2, 2, 3])).toList()}');
  print('variance: ${variance(a)}');
  print('standard deviation: ${standardDeviation(a)}');
}
Output
mean: 5.0
median: 4.5
mode: 4.0
multimode: [1.0, 2.0]
variance: 4.571428571428571
standard deviation: 2.138089935299395
  • variance and standardDeviation use the sample formula, dividing by n - 1. This matches numpy.var(a, ddof=1), not the NumPy default.
  • median does not change the order of the input.
  • mode returns the first of the most frequent values, in the order they appear; multimode returns all of them in that order.

For probability distributions, see Normal distribution.

Loading the interactive demo…

Edit this guide on GitHub