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) # We'll use temp = 212, the boiling point of water, which was incorrect print "212 - 32:", 212 - 32 print "(212 - 32) * (5/9):", (212 - 32) * (5/9) 5/9 print '10/3 is:', 10/3 print '10.0/3 is:', 10.0/3 def fahr_to_kelvin(temp): return ((temp - 32) * (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 kelvin_to_celsius(temp): return temp - 273.15 print 'absolute zero in Celsius:', kelvin_to_celsius(0.0) 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) original = 32.0 final = fahr_to_celsius(original) print 'final value of temp after all function calls:', temp import numpy def span(a): diff = a.max() - a.min() return diff data = numpy.loadtxt(fname='inflammation-01.csv', delimiter=',') print 'span of data', span(data) diff = numpy.loadtxt(fname='inflammation-01.csv', delimiter=',') print 'span of data:', span(diff) def center(data, desired): return (data - data.mean()) + desired z = numpy.zeros((2,2)) print center(z, 3) data = numpy.loadtxt(fname='inflammation-01.csv', delimiter=',') print center(data, 0) print 'original min, mean, and max are:', data.min(), data.mean(), data.max() centered = center(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 'difference in standard deviations before and after:', data.std() - centered.std() # center(data, desired): return a new array containing the original data centered around the desired value. def center(data, desired): return (data - data.mean()) + desired def center(data, desired): '''Return a new array containing the original data centered around the desired value.''' return (data - data.mean()) + desired help(center) def center(data, desired): '''Return a new array containing the original data centered around the desired value. Example: center([1, 2, 3], 0) => [-1, 0, 1]''' return (data - data.mean()) + desired help(center) numpy.loadtxt('inflammation-01.csv', delimiter=',') numpy.loadtxt('inflammation-01.csv', ',') def center(data, desired=0.0): '''Return a new array containing the original data centered around the desired value (0 by default). Example: center([1, 2, 3], 0) => [-1, 0, 1]''' return (data - data.mean()) + desired test_data = numpy.zeros((2, 2)) print center(test_data, 3) more_data = 5 + numpy.zeros((2, 2)) print 'data before centering:', more_data print 'centered data:', center(more_data) def display(a=1, b=2, c=3): print 'a:', a, 'b:', b, 'c:', c print 'no parameters:' display() print 'one parameter:' display(55) print 'two parameters:' display(55, 66) print 'only setting the value of c' display(c=77) help(numpy.loadtxt)