In [1]:
    
import numpy
    
In [2]:
    
#assuming the data file is in the data/ folder
numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
    
    Out[2]:
numpything.component=
In [3]:
    
weight_kg = 55 #assigns value 55 to weight_kg
    
In [4]:
    
print(weight_kg) #we can print to the screen
    
    
In [5]:
    
print('weight in pounds:', 2.2 * weight_kg) # do arithmetic with it
    
    
In [6]:
    
print?
    
In [7]:
    
weight_kg = 57.5 #change variable's value by assign new value
print('weight in kilograms is now :', weight_kg)
    
    
In [7]:
    
weight_lb = 2.2 * weight_kg #example let's store patients weight in pounds
print('weight in kilograms: ', weight_kg, 'and in pounds', weight_lb)
    
    
In [8]:
    
weight_kg = 100.0 #now change weight_kg
print('weight in kilograms is now:', weight_kg, 'and weight in pounds is still:', weight_lb)
    
    
weight_lb dosn't remember where its value came fromweight_kg changes - not like spreadsheetswhos #ipython command to see what variables & mods you have
In [9]:
    
whos
    
    
numpy.loadtxt and save its result
In [6]:
    
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
    
In [4]:
    
print(data) #statement above doesn't produce output, let's pring
    
    
In [12]:
    
print(type(data)) #we can get type of object
    
    
In [13]:
    
print(data.shape)
    
    
data has 60 rows and 40 columns 
In [14]:
    
print('first value in data', data[0,0]) #use index in square brackets
    
    
In [15]:
    
data[30,20] # get the middle value - notice here i didn't use print
    
    Out[15]:
In [16]:
    
data[0:4, 0:10] #select whole sections of matrix, 1st 10 days & 4 patients
    
    Out[16]:
In [17]:
    
data[5:10,0:10]
    
    Out[17]:
: will include everything
In [18]:
    
data[:3, 36:]
    
    Out[18]:
element = 'oxygen'
print('first three characters:', element[0:3])
print('last three characters:', element[3:6])
first three characters: oxy
last three characters: gen
What is the value of element[:4]? What about element[4:]? Or element[:]?
What is element[-1]? What is element[-2]? Given those answers, explain what element[1:-1] does.
In [1]:
    
element = 'oxygen'
print('first three characters:', element[0:3])
print('last three characters:', element[3:6])
    
    
In [6]:
    
print(element[:4])
print(element[4:])
    
    
In [7]:
    
print(:)
    
    
In [14]:
    
#oxygen
print(element[-1])
print(element[-2])
print(element[2:-1])
    
    
In [13]:
    
doubledata = data * 2.0 #we can perform math on array
    
    
In [20]:
    
doubledata
    
    Out[20]:
In [21]:
    
data[:3, 36:]
    
    Out[21]:
In [22]:
    
doubledata[:3, 36:]
    
    Out[22]:
In [23]:
    
tripledata = doubledata + data
    
In [24]:
    
print('tripledata:')
print(tripledata[:3, 36:])
    
    
In [25]:
    
print(data.mean())
    
    
mean we need empty () parense even if we aren't passing in parameters to tell python to go do somethingdata.shape doesn't need () because it's just a description 
In [26]:
    
print('maximum inflammation: ', data.max())
print('minimum inflammation: ', data.min())
print('standard deviation:', data.std())
    
    
In [8]:
    
patient_0 = data[0, :] #0 on first axis, everythign on second
print('maximum inflammation for patient 0: ', patient_0.max())
    
    
In [15]:
    
data[2, :].max() #max inflammation of patient 2
    
    Out[15]:
In [9]:
    
print(data.mean(axis=0))
    
    
In [30]:
    
print(data.mean(axis=0).shape) #Nx1 vector of averages
    
    
In [31]:
    
print(data.mean(axis=1)) #avg inflam per patient across all days
    
    
In [32]:
    
print(data.mean(axis=1).shape)
    
    
matplotlib library
In [3]:
    
import matplotlib.pyplot
    
In [7]:
    
image = matplotlib.pyplot.imshow(data)
    
    
In [10]:
    
matplotlib.pyplot.imshow?
    
% indicates an ipython magic function 
In [4]:
    
%matplotlib inline
    
In [12]:
    
numpy.mean?
    
now let's look at avg inflammation over days (columns)
In [14]:
    
ave_inflammation = data.mean(axis = 0)
ave_plot = matplotlib.pyplot.plot(ave_inflammation)
matplotlib.pyplot.show(ave_plot)
    
    
In [36]:
    
max_plot = matplotlib.pyplot.plot(data.max(axis=0))
matplotlib.pyplot.show(max_plot)
    
    
In [37]:
    
min_plot = matplotlib.pyplot.plot(data.min(axis=0))
matplotlib.pyplot.show(min_plot)
    
    
matplotlib.pyplot.figure() create the plotting spacefigsize tells python how bigadd_subplot set_xlabel() & set_ylabel set the titles fo the axes 
In [ ]:
    
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()
    
    
In [ ]: