-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamplenumpy14.py
More file actions
41 lines (34 loc) · 1.46 KB
/
examplenumpy14.py
File metadata and controls
41 lines (34 loc) · 1.46 KB
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
import numpy as np
import matplotlib.pyplot as plt
def examplehistogram():
a = np.array([89, 34, 56, 87, 90, 23, 45, 12, 65, 78, 9, 34, 12, 11, 2 ,65, 78, 82, 28, 78])
histogram=np.histogram(a)
print(histogram)
'''
histogram
(array([2, 3, 2, 2, 1, 0, 1, 2, 3, 4], dtype=int64), array([ 2. , 10.8, 19.6, 28.4, 37.2, 46. , 54.8, 63.6, 72.4, 81.2, 90. ]))
'''
histogram2 = np.histogram(a,bins=2)
print(histogram2) # (array([10, 10], dtype=int64), array([ 2., 46., 90.]))
histogram3=np.histogram(a, bins=[0,30,60,90])
print(histogram3) #(array([7, 4, 9], dtype=int64), array([ 0, 30, 60, 90]))
histogram4=np.histogram(a, bins=5, density=True) #density 확률 값
print(histogram4) #(array([0.01420455, 0.01136364, 0.00284091, 0.00852273, 0.01988636]), array([ 2. , 19.6, 37.2, 54.8, 72.4, 90. ]))
def exampledrawing():
a = np.array([89, 34, 56, 87, 90, 23, 45, 12, 65, 78, 9, 34, 12, 11, 2 ,65, 78, 82, 28, 78])
plt.hist(a, color='green', alpha=0.4) #alpha: 투명도
plt.title("my histogram")
plt.show()
def exampledrawing2():
a = np.array([89, 34, 56, 87, 90, 23, 45, 12, 65, 78, 9, 34, 12, 11, 2 ,65, 78, 82, 28, 78])
histogram2 = np.histogram(a,bins=2)# (array([10, 10], dtype=int64), array([ 2., 46., 90.]))
plt.hist(histogram2)
plt.title("histogram")
plt.show()
def main():
print("histogram")
examplehistogram()
exampledrawing()
exampledrawing2()
if __name__=="__main__":
main()