-
-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathmoment_generating_function.py
126 lines (78 loc) · 2.48 KB
/
moment_generating_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#1-Dimensional Data:
#Import required libraries:
from scipy import stats
#Dataset:
d = [1,2,3,4,5]
#Finding 0th moment:
print("0th Moment = ",stats.moment(d,moment=0))
#Finding 1st moment:
print("1st Moment = ",stats.moment(d,moment=1))
#Finding 2nd moment:
print("2nd Moment = ",stats.moment(d,moment=2))
#Finding 3nd moment:
print("3nd Moment = ",stats.moment(d,moment=3))
#Finding 4th moment:
print("4th Moment = ",stats.moment(d,moment=4))
#============================================================
#2-Dimensional Data:
#Import required libraries:
from scipy import stats
#Dataset:
d = [[5,6,9,11,3],[21,4,8,15,2]]
#Finding 0th moment:
print("0th Moment = ",stats.moment(d,moment=0))
#Finding 1st moment:
print("1st Moment = ",stats.moment(d,moment=1))
#Finding 2nd moment:
print("2nd Moment = ",stats.moment(d,moment=2))
#Finding 3nd moment:
print("3nd Moment = ",stats.moment(d,moment=3))
#Finding 4th moment:
print("4th Moment = ",stats.moment(d,moment=4))
#============================================================
#2-Dimensional Data:
#Set axis=1 (Horizonatal):
#Import required libraries:
from scipy import stats
#Dataset:
d = [[5,6,9,11,3],[21,4,8,15,2]]
#Finding 0th moment:
print("0th Moment = ",stats.moment(d,moment=0,axis=1))
#Finding 1st moment:
print("1st Moment = ",stats.moment(d,moment=1,axis=1))
#Finding 2nd moment:
print("2nd Moment = ",stats.moment(d,moment=2,axis=1))
#Finding 3nd moment:
print("3nd Moment = ",stats.moment(d,moment=3,axis=1))
#Finding 4th moment:
print("4th Moment = ",stats.moment(d,moment=4,axis=1))
#============================================================
#Multi-Dimensional Data:
#Import required libraries:
from scipy import stats
#Dataset:
d = [[5,6,9,11,3],
[21,4,8,15,2],
[15,23,42,1,36]]
#Finding 0th moment:
print("0th Moment = ",stats.moment(d,moment=0))
#Finding 1st moment:
print("1st Moment = ",stats.moment(d,moment=1))
#Finding 2nd moment:
print("2nd Moment = ",stats.moment(d,moment=2))
#Finding 3nd moment:
print("3nd Moment = ",stats.moment(d,moment=3))
#Finding 4th moment:
print("4th Moment = ",stats.moment(d,moment=4))
#============================================================
#2-Dimensional Data:
#Set axis=1 (Horizonatal):
#Higher Order Moments:
#Import required libraries:
from scipy import stats
#Dataset:
d = [[5,6,9,11,3],[21,4,8,15,2]]
#Finding 10th moment:
print("10th Moment = ",stats.moment(d,moment=10,axis=1))
#Finding 12th moment:
print("12th Moment = ",stats.moment(d,moment=12,axis=1))