Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168732
Image: ubuntu2004
""" Exercise 1 Statistical measures of a small sample """ import numpy as np x = np.array([12.1,12.3,12.2,12.2,12.4,12.3,12.2,12.4,12.2,12.5]) x_mean = np.mean(x) x_median = np.median(x) x_variance = np.var(x) x_std = np.std(x) x_modes = np.histogram(x) x_mode_ind = np.argmax(x_modes[0]) x_mode_count = x_modes[0][x_mode_ind] x_mode_val = x[x_mode_ind] print "Mean: %f " % x_mean print "Median: %f" % x_median print "Variance: %f" % x_variance print "STD: %f " % x_std print "Mode of x %f appears %d times" % (x_mode_val,x_mode_count)
Mean: 12.280000 Median: 12.250000 Variance: 0.013600 STD: 0.116619 Mode of x 12.200000 appears 4 times