print("test")
import numpy
numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
weight_kg = 55
print(weight_kg)
print('weight in pounds:', 2.2 * weight_kg)
weight_kg = 57.5
print('weight in kilograms is now:', weight_kg)
weight_lb = 2.2 * weight_kg
print('weight in kilograms:', weight_kg, 'and in pounds:', weight_lb)
weight_kg = 100
print('weight in kilograms is now:', weight_kg,
'and weight in pounds is..', weight_lb)
weight_kg = "hello"
print(weight_kg)
print(weight_lb)
weight_kg = 100
whos
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
print(data)
print(type(data))
data.size
data.shape
print(data.shape)
print('first value in data:', data[0,0])
print('middle value in data:', data[30,20])
print(data[0:4, 0:10])
small = data[:3, 36:]
print('small is:')
print(small)
doubledata = data * 2.0
print('original:')
print(data[:3, 36:])
print('doubledata:')
print(doubledata[:3, 36:])
tripledata = doubledata + data
print(tripledata[:3, 36:])
print(data.mean())
print(doubledata.mean())
data.shape
print(data.max())
print(data.min())
print(data.std())
patient_0 = data[0, :]
print('maximum inflammation for patient 0:', patient_0.max())
print(patient_0)
print(patient_0.mean())
print(data.mean(axis=0))
data.shape
%matplotlib inline
import matplotlib.pyplot
image = matplotlib.pyplot.imshow(data)
matplotlib.pyplot.show()
ave_inflammation = data.mean(axis=0)
ave_plot = matplotlib.pyplot.plot(ave_inflammation)
matplotlib.pyplot.show(ave_plot)
max_plot = matplotlib.pyplot.plot(data.max(axis=0))
matplotlib.pyplot.show()
min_plot = matplotlib.pyplot.plot(data.min(axis=0))
matplotlib.pyplot.show(min_plot)
import numpy
import matplotlib.pyplot
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
fig = matplotlib.pyplot.figure(figsize=(10.0, 3.0))
axes1 = fig.add_subplot(1,3,1)
axes2 = fig.add_subplot(1,3,2)
axes3 = fig.add_subplot(1,3,3)
axes1.set_ylabel('average')
axes1.plot(data.mean(axis=0))
axes2.set_ylabel('max')
axes2.plot(data.max(axis=0))
axes3.set_ylabel('min')
axes3.plot(data.min(axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
import numpy
import matplotlib.pyplot
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
fig = matplotlib.pyplot.figure(figsize=(10.0,3.0))
axes1 = fig.add_subplot(1,4,1)
axes2 = fig.add_subplot(1,4,2)
axes3 = fig.add_subplot(1,4,3)
axes4 = fig.add_subplot(1,4,4)
axes1.set_ylabel('Average')
axes1.plot(data.mean(axis=0))
axes2.set_ylabel('Maximum')
axes2.plot(data.max(axis=0))
axes3.set_ylabel('Minimum')
axes3.plot(data.min(axis=0))
axes4.set_ylabel('Standard Deviation')
axes4.plot(data.std(axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
word = 'lead'
print(word[0])
print(word[1])
print(word[2])
print(word[3])
print(word)
word = "oxygen"
for char in word:
print(char)
length = 0
for vowel in 'aeiouhippo':
length = length + 1
print('There are', length, 'vowels, and the vowel is', vowel)
my_string = 'kjasgoijaefjihadfjohoidafjhjadfh'
print(len(my_string))
my_string = 'hello'
for x in range(len(my_string)):
print(my_string[x])
for x in my_string:
print(x)
print(5 ** 3)
power = 4
base = 2
result = base
for x in range(1,power):
result = result * base
print(result)
res = 1
for x in range(3):
res = res*5
print(res)
exponent = 3
value = 3
result = 1
for i in range(1,exponent+1) :
result = result * value
print(result)
exp = 5
num = 10
result = 1
for x in range(exp):
result = result*num
print(result)
challenge = 'Newton'
reverse = ''
for ??? in ???:
???
print(reverse)
# notweN
challenge[0]
challenge = 'Newton'
long = len(challenge)
for x in range(long-1,-1,-1):
#print(-x)
now = challenge[-x]
print(now, end='')
challenge = 'Newton'
length = 0
for char in challenge:
length = length + 1
count = 0 - length
print(count)
#print(challenge[count], end='')
word = "Newton"
reverse = ''
for i in range(len(word)-1, -1, -1):
reverse = reverse + word[i]
print(reverse)
odds = [1, 3, 5, 7]
len(odds)
print('first andlast: ', odds[0], odds[-2])
for number in odds:
print(number)
somelist = ["bla", 11234, 1.124124]
b = "ASDFG"
b[1] = "Z"
a = ['A', 'S', 'D', 'F']
a[1] = 'Z'
print(a)
''.join(a)
print(list(b))
b
x = [['pepper', 'zucchini', 'onion'],
['cabbage', 'lettuce', 'garlic'],
['apple', 'pear', 'banana']]
print(x)
print(x[0])
print(x[0][0])
odds.append(9)
print(odds)
del odds[0]
print(odds)
odds.reverse()
print(odds)
odds.extend(['a', 'c', 'b'])
print(odds)
odds =[1,3,5,7]
primes = odds
primes += [2]
print('this is primes: ', primes)
print('this is odds: ', odds)
primes = list(odds)
primes[0] = 'bla'
print('this is primes: ', primes)
print('this is odds: ', odds)
hello = 'hello'
hello_list = ['h', 'e', 'l', 'l', 'o']
my_list = []
my_list = ['e']
for c in hello:
my_list
print(my_list)
string_to_break = 'hello'
string_list = []
for letter in string_to_break:
string_list.append(letter)
print(string_list)
string_list.sort()
string_list.pop()
string_list.pop()
string_list.pop()
string_list.pop()
string_list.pop()
string_list.pop()
this_tuple = 1, 2, 3
a, b, c = this_tuple
print(a)
left = 'L'
right = 'R'
temp = left
left = 'BLA'
# left = right
right = temp
print('left =', left)
print('right =', right)
print('temp = ', temp)
left = 'L'
right = 'R'
left, right = (right, left)
print('left =', left)
print('right =', right)
import glob
print(glob.glob('data/inflammation*.csv'))
%matplotlib inline
import numpy
import matplotlib.pyplot
filenames = glob.glob('data/inflammation*.csv')
filenames.sort()
filenames = filenames[0:3]
for f in filenames:
print(f)
data = numpy.loadtxt(fname=f, delimiter=',')
if data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:
print("Suspicious looking maxima !!!1!")
elif data.min(axis=0).sum() == 0:
print("Minima add up to zero !")
else:
print("Seems okay. :)")
fig = matplotlib.pyplot.figure(figsize=(10.0, 3.0))
axes1 = fig.add_subplot(1 ,3, 1)
axes2 = fig.add_subplot(1, 3, 2)
axes3 = fig.add_subplot(1, 3, 3)
axes1.set_ylabel('average')
axes1.plot(data.mean(axis=0))
axes2.set_ylabel('max')
axes2.plot(data.max(axis=0))
axes3.set_ylabel('min')
axes3.plot(data.min(axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
print(filenames)
type(data)
num = 37
if num > 100:
print('greater')
else:
print('not greater')
print('done')
num = 53
print ('before')
if num > 100:
print('53 is greater than 100')
print('after')
num = -3
if num > 0:
print(num, 'is +ve')
elif num == 0:
print(num, 'is zero')
else:
print(num, 'is -ve')
if (1 < 0) and (-1 < 0): # False and True
print('both parts are True')
else:
print('at least one part is False')
if (1 < 0) or (-1 < 0): # False and True
print('at least one test is True')
if data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:
print("Suspicious looking maxima !!!1!")
data = numpy.loadtxt(fname='data/inflammation-03.csv', delimiter=',')
if data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:
print("Suspicious looking maxima !!!1!")
elif data.min(axis=0).sum() == 0:
print("Minima add up to zero !")
else:
print("Seems okay. :)")
4 = 5
if 4 > 5:
print('A')
elif 4 == 5:
print('B')
elif 4 < 5:
print('C')
# Hmmmmmm. Will it print A ? Nope, 4 is not greater than 5
# Will it print B ?
this_is_a_bool = True
an_another = False
if '':
print('empty string is True')
if 'word':
print('word is True')
if []:
print('empty list is True')
if [1,2,4]:
print('list with stuff is True')
if 0:
print('the number zero is True')
if 1:
print('the number one is True')
if None:
print('None is True')
bla = " blblbl "
print(bla)
print(bla.strip())
if not bla.strip():
print("bla is empty")
a = 100
b = 95
print(a == b)
print(a > b * 2)
print((a > 10 * b) and (a < 2 * b))
# print( (a ? < .. ?) and (a ? > ..?))
threshold = 2
if a > b*(1 - threshold/100) and a < b*(1 + threshold/100):
print('a is within %s percent of b' % threshold)
else:
print('a is not within %s percent of b' % threshold)
x = 1
x += 1 # x = x + 1
print(x)
x *= 10
print(x)
nums = [-1, -3, -5, 2, 4, 8]
pos_sum = 0
neg_sum = 0
for n in nums:
# something in here that uses in-place += operator ...
pass
def fahr_to_kelvin(temp):
return ((temp - 32) * (5/9)) + 273.15
print('freezing point of water:', fahr_to_kelvin(32))
print('boiling point of water:', fahr_to_kelvin(212))
def kelvin_to_celsius(temp_k):
return temp_k - 273.15
print('absolute zero in celsius:', kelvin_to_celsius(0.0))
def fahr_to_celsius(temp_f):
temp_k = fahr_to_kelvin(temp_f)
result = kelvin_to_celsius(temp_k)
return result
print('freezing point of water in celsius:', fahr_to_celsius(32.0))
def analyze(filename):
data = numpy.loadtxt(fname=filename, delimiter=',')
fig = matplotlib.pyplot.figure(figsize=(10.0, 3.0))
axes1 = fig.add_subplot(1, 3, 1)
axes2 = fig.add_subplot(1, 3, 2)
axes3 = fig.add_subplot(1, 3, 3)
axes1.set_ylabel('average')
axes1.plot(data.mean(axis=0))
axes2.set_ylabel('max')
axes2.plot(data.max(axis=0))
axes3.set_ylabel('min')
axes3.plot(data.min(axis=0))
fig.tight_layout()
matplotlib.pyplot.show()
def detect_problems(filename):
data = numpy.loadtxt(fname=filename, delimiter=',')
if data.max(axis=0)[0] == 0 and data.max(axis=0)[20] == 20:
print("Suspicious looking maxima !!!1!")
elif data.min(axis=0).sum() == 0:
print("Minima add up to zero !")
else:
print("Seems okay. :)")
import numpy
import matplotlib.pyplot
filenames = glob.glob('data/inflammation*.csv')
filenames.sort()
filenames = filenames[0:3]
for f in filenames:
print(f)
analyze(f)
detect_problems(f)
def center(data, desired=0.0):
'''Return a new array containing the original data centered around the desired value'''
return (data - data.mean()) + desired
help(data.max)
z = numpy.zeros((2,2))
print(z)
print(center(z, 3))
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
print(center(data))
print('original min, mean and max are: ', data.min(), data.mean(), data.max())
centered = center(data, 0)
print('min, mean and max of centered data are:', centered.min(),
centered.mean(), centered.max())
print(data.std())
print(centered.std())
numpy.loadtxt('data/inflammation-01.csv', delimiter=',')
def display(a=1, b=2, c=3):
print('a:',a,'b:',b,'c:',c)
display()
display(55, c=66)
help(numpy.loadtxt)
def fence(original, wrapper):
result = wrapper + original + wrapper
return result
print(fence('name', '*'))
print("{first_name} {last_name}".format(first_name="john", last_name="smith"))