In [34]:
import numpy as np
from scipy.stats import t

np.random.seed(32)

x = np.random.normal(3.2,2.0,size=10)

print(x)

mean = np.sum(x)/len(x)
variance =  np.sum(((x - mean)**2)/(len(x)-1))
print(mean,variance,np.sqrt(variance))

tval = (mean - 3.2)/(np.sqrt(variance)/np.sqrt(10))
print(tval)

#tdist = scipy.stats.t
#scipy.stats.t.pdf(3)
cdf = t.cdf(tval,df=9)

print( (1.-cdf)*2)

scipy.stats.ttest_1samp(x,popmean=3.2)


[2.5022111  5.16740687 4.36184566 3.34056888 4.75506535 4.36391749
 6.14358105 6.52636202 2.67764576 1.82264637]
4.166125055407907 2.4517234099102936 1.5657980105717
1.9511812245373021
0.08280947069921618
Out[34]:
Ttest_1sampResult(statistic=1.951181224537302, pvalue=0.08280947069921618)