import numpy as np
Twelve data points given. Enter them into a numpy
array:
data = np.array([5.33, 4.95, 4.93, 5.08, 4.95, 4.96, 5.02, 4.99, 5.24, 5.25, 5.23, 5.01])
print('mean = ', np.sum(data)/len(data))
OR
print('mean = ', np.mean(data))
print("standard deviation = ",np.sqrt(np.sum((data-np.mean(data))**2)/(len(data)-1)))
OR
print("standard deviation = ",np.std(data))
These results do not agree!!
By default the numpy std
function calculates $\sigma_N$, which is similar to the $\sigma_{N−1}$
given in Eq. (2.3) of H&H, except the denominator is $N$ instead of $N−1$.
The difference doesn't usually matter, and we won't go into this in any depth now. But if we
set the ddof=1
option, numpy
will calculate $\sigma_{N−1}$.
Remember: you can see all the details of np.std
by typing np.std?
.
print("standard deviation = ", np.std(data, ddof=1))
Use Eq. (2.7): $$\quad \alpha = \frac{\sigma_{N-1}}{\sqrt{N}}. $$
print("standard error =", np.std(data, ddof=1)/np.sqrt(len(data)))
Sensitivity = $5.08 \pm 0.04\, \mbox{A/W}$
version_information
is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.
version_information
is installed on the linux network at Bucknell
%load_ext version_information
%version_information numpy