-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
135 lines (82 loc) · 2.67 KB
/
Copy pathtest.py
File metadata and controls
135 lines (82 loc) · 2.67 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
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
127
128
129
130
131
132
import numpy as np
import glob
from matplotlib import pyplot
fdata='teaching/swc-python/novice/inflammation-01.csv'
data=np.loadtxt(fname='teaching/swc-python/novice/inflammation-01.csv', delimiter=',')
print data
print data[0:4, 1]
print type(data)
print data.shape
print 'first value in data:', data[0, 0]
print 'almost middle value in data:', data[30, 20]
print data[0:4, 0:10]
print data[0:10:3, 0:10:2]
print data.mean()
print 'maximum inflammation:', data.max()
print 'minimum inflammation:', data.min()
print 'standard deviation:', data.std()
patient_0 = data[0, :] # 0 on the first axis, everything on the second
print 'maximum inflammation for patient 0:', patient_0.max()
print data.mean(axis=0)
pyplot.imshow(data)
pyplot.show()
def fahr_to_kelvin(temp):
return ((temp-32.0)*5.0/9.0+273+.15)
print 'freezing point of water', fahr_to_kelvin(32)
print 'boiling point of water', fahr_to_kelvin(212)
def fahr_to_kelvin_2(temp):
return ((temp-32)*5/9+273+.15)
print 'freezing point of water 2', fahr_to_kelvin_2(32)
print 'boiling point of water 2', fahr_to_kelvin_2(212)
def kelvin_to_celsius(temp):
return (temp-273.15)
def fahr_to_celsius(temp):
temp_k = fahr_to_kelvin(temp)
result = kelvin_to_celsius(temp_k)
return result
print 'freezing point of water in Celsius:', fahr_to_celsius(32.0)
def fence(original,wrapper):
return wrapper+original+wrapper
print 'fence string: ', fence('paul','kial')
def outer(original):
return original[0]+original[-1]
print 'original string: ', outer('helium')
def centre(data,desired):
'Return a new array containing the original data centered around the desired value.'
return (data-data.mean()) +desired
#help(centre)
z=np.zeros((2,2))
z=centre(z,3)
print z
def span(a):
'max -min of data'
diff = a.max() - a.min()
return diff
print 'span of data', span(data)
print 'original min, mean, and max are:', data.min(), data.mean(), data.max()
centered = centre(data, 0)
print 'min, mean, and and max of centered data are:', centered.min(), centered.mean(), centered.max()
print 'std dev before and after:', data.std(), centered.std()
print outer(fence('carbon', '+'))
def analyze(fname):
ave = data.mean(axis=0)
pyplot.plot(ave)
pyplot.show()
pyplot.plot(data.max(axis=0))
pyplot.show()
print 'minimum inflammation per day'
pyplot.plot(data.min(axis=0))
pyplot.show()
analyze(fdata)
def rescale(a):
result=(a[:]-a.max())/(a.max()-a.min())
return result
a=np.random.rand(3,2)
#start (0default), stop, step
#aa=range(0,100,5)
b=rescale(a)
print 'rescale rand', a
#for loops
def print_characters(element):
for char in elelment:
print char