In [2]:
import numpy
In [3]:
#assuming the data file is in the data/ folder
numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
Out[3]:
numpy
thing.component
=
In [4]:
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
In [5]:
print(data)
In [7]:
weight_kg = 55 #assigns value 55 to weight_kg
In [8]:
print(weight_kg) #we can print to the screen
In [9]:
print("weight in kg", weight_kg)
In [15]:
weight_kg = 70
In [11]:
print("weight in kg", weight_kg)
In [12]:
weight_kg * 2
Out[12]:
In [16]:
weight_lb = weight_kg * 2.2
In [17]:
print('weigh in lb:', weight_lb)
In [18]:
print("weight in lb:", weight_kg*2.2)
In [19]:
print(data)
whos #ipython command to see what variables & mods you have
In [20]:
whos
In [21]:
print(data)
In [22]:
print(type(data)) #we can get type of object
In [23]:
print(data.shape)
data
has 60 rows and 40 columns
In [24]:
print('first value in data', data[0,0]) #use index in square brackets
In [26]:
print('4th value in data', data[0,3]) #use index in square brackets
In [32]:
print('first value in 3rd row data', data[3,0]) #use index in square brackets
In [31]:
!head -3 data/inflammation-01.csv
In [33]:
print('middle value in data', data[30,20]) # get the middle value - notice here i didn't use print
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 [34]:
%matplotlib inline
In [36]:
import matplotlib.pyplot as plt
In [37]:
data
Out[37]:
matplotlib
library
In [38]:
plt.imshow(data)
Out[38]:
In [39]:
image = plt.imshow(data)
plt.savefig('timsheatmap.png')
%
indicates an ipython magic function
In [44]:
avg_inflam = data.mean(axis=0) #asix zero is by each day
In [45]:
print(data.mean(axis=0))
In [46]:
print(data.mean(axis=0).shape) #Nx1 vector of averages
In [47]:
print(data.mean(axis=1)) #avg inflam per patient across all days
In [48]:
print(data.mean(axis=1).shape)
now let's look at avg inflammation over days (columns)
In [49]:
print(avg_inflam)
In [51]:
day_avg_plot = plt.plot(avg_inflam)
In [52]:
data.mean(axis=0).shape
Out[52]:
In [53]:
data.shape
Out[53]:
In [54]:
data.mean(axis=1).shape
Out[54]:
In [55]:
max_plot = plt.plot(data.max(axis=0))
In [ ]: