Variance, skewness and kurtosis

import numpy as np from scipy.stats import skew, kurtosis labels = ['Variance', 'Skewness', 'Kurtosis'] label_descs = ['how values spread around the mean', 'measure of asymmetry', 'measure of peakedness'] seq = [35, 24, 18, 44, 61, 17, 19, 21, 27, 37] mean_seq = sum(seq) / len(seq) lib_vals = [np.var(seq), skew(seq), kurtosis(seq, fisher=False)] print("Sequence: %s" % (seq)) for i in range(3): s = sum([(el - mean_seq) ** (i+2) for el in seq]) / len(seq) if i == 0: std = s ** 0.5 else: s /= std ** (i+2) print("%s (%s): %f, %s" % (labels[i], label_descs[i], s, np.allclose(s, lib_vals[i]))) """ Sequence: [35, 24, 18, 44, 61, 17, 19, 21, 27, 37] Variance (how values spread around the mean): 179.010000, True Skewness (measure of asymmetry): 1.050649, True Kurtosis (measure of peakedness): 3.138365, True """