In [2]:
pwd


Out[2]:
u'/home/pvh/Desktop/python/data'

In [3]:
import numpy


Vendor:  Continuum Analytics, Inc.
Package: mkl
Message: trial mode expires in 30 days

In [4]:
numpy.loadtxt(fname='inflammation-01.csv', delimiter=',')


Out[4]:
array([[ 0.,  0.,  1., ...,  3.,  0.,  0.],
       [ 0.,  1.,  2., ...,  1.,  0.,  1.],
       [ 0.,  1.,  1., ...,  2.,  1.,  1.],
       ..., 
       [ 0.,  1.,  1., ...,  1.,  1.,  1.],
       [ 0.,  0.,  0., ...,  0.,  2.,  0.],
       [ 0.,  0.,  1., ...,  1.,  1.,  0.]])

In [5]:
weight_kg = 55

In [6]:
print(weight_kg)


55

In [10]:
print 'Weight in pounds:', 2.2 * weight_kg


Weight in pounds: 121.0

In [19]:
weight_in_pounds = weight_kg * 2.2

In [20]:
print 'Weight in pounds:', weight_in_pounds


Weight in pounds: 126.5

In [17]:
weight_kg = 57.5 
print 'Weight in kg:', weight_kg


Weight in kg: 57.5

In [21]:
data = numpy.loadtxt(fname='inflammation-01.csv', delimiter=',')

In [22]:
print data


[[ 0.  0.  1. ...,  3.  0.  0.]
 [ 0.  1.  2. ...,  1.  0.  1.]
 [ 0.  1.  1. ...,  2.  1.  1.]
 ..., 
 [ 0.  1.  1. ...,  1.  1.  1.]
 [ 0.  0.  0. ...,  0.  2.  0.]
 [ 0.  0.  1. ...,  1.  1.  0.]]

In [23]:
print type(data)


<type 'numpy.ndarray'>

In [25]:
print data.shape


(60, 40)

In [26]:
print 'first value in the data:', data[0, 0]


first value in the data: 0.0

In [27]:
print 'middle value of the data:', data[30, 20]


middle value of the data: 13.0

In [28]:
print 'let us look at a slice'
print data[0:4, 0:10]


let us look at a slice
[[ 0.  0.  1.  3.  1.  2.  4.  7.  8.  3.]
 [ 0.  1.  2.  1.  2.  1.  3.  2.  2.  6.]
 [ 0.  1.  1.  3.  3.  2.  6.  2.  5.  9.]
 [ 0.  0.  2.  0.  4.  2.  2.  1.  6.  7.]]

In [29]:
print data[:4, :10]


[[ 0.  0.  1.  3.  1.  2.  4.  7.  8.  3.]
 [ 0.  1.  2.  1.  2.  1.  3.  2.  2.  6.]
 [ 0.  1.  1.  3.  3.  2.  6.  2.  5.  9.]
 [ 0.  0.  2.  0.  4.  2.  2.  1.  6.  7.]]

In [30]:
print data[:3, 36:]


[[ 2.  3.  0.  0.]
 [ 1.  1.  0.  1.]
 [ 2.  2.  1.  1.]]

In [31]:
answer = 4 * 2
print answer


8

In [32]:
doubledata = data * 2.0

In [33]:
print 'original:'
print data
print 'doubledata:'
print doubledata


original:
[[ 0.  0.  1. ...,  3.  0.  0.]
 [ 0.  1.  2. ...,  1.  0.  1.]
 [ 0.  1.  1. ...,  2.  1.  1.]
 ..., 
 [ 0.  1.  1. ...,  1.  1.  1.]
 [ 0.  0.  0. ...,  0.  2.  0.]
 [ 0.  0.  1. ...,  1.  1.  0.]]
doubledata:
[[ 0.  0.  2. ...,  6.  0.  0.]
 [ 0.  2.  4. ...,  2.  0.  2.]
 [ 0.  2.  2. ...,  4.  2.  2.]
 ..., 
 [ 0.  2.  2. ...,  2.  2.  2.]
 [ 0.  0.  0. ...,  0.  4.  0.]
 [ 0.  0.  2. ...,  2.  2.  0.]]

In [34]:
tripledata = doubledata + data

In [35]:
print 'tripledata'
print tripledata[:3, 36:]


tripledata
[[ 6.  9.  0.  0.]
 [ 3.  3.  0.  3.]
 [ 6.  6.  3.  3.]]

In [37]:
print data.mean()


6.14875

Now I can write documentation together with my code


In [39]:
print data.max()
print data.min()
print data.std()


20.0
0.0
4.61383319712

In [43]:
patient_0 = data[0, :]
print 'maximum inflammation for patient zero:', patient_0.max()


maximum inflammation for patient zero: 18.0

In [44]:
print 'max inflammation for patient 2:', data[2, :].max()


max inflammation for patient 2: 19.0

In [45]:
print data.mean(axis=0)


[  0.           0.45         1.11666667   1.75         2.43333333   3.15
   3.8          3.88333333   5.23333333   5.51666667   5.95         5.9
   8.35         7.73333333   8.36666667   9.5          9.58333333
  10.63333333  11.56666667  12.35        13.25        11.96666667
  11.03333333  10.16666667  10.           8.66666667   9.15         7.25
   7.33333333   6.58333333   6.06666667   5.95         5.11666667   3.6
   3.3          3.56666667   2.48333333   1.5          1.13333333
   0.56666667]

In [46]:
print data.mean(axis=0).shape


(40,)

In [47]:
print data.shape


(60, 40)

In [48]:
print data


[[ 0.  0.  1. ...,  3.  0.  0.]
 [ 0.  1.  2. ...,  1.  0.  1.]
 [ 0.  1.  1. ...,  2.  1.  1.]
 ..., 
 [ 0.  1.  1. ...,  1.  1.  1.]
 [ 0.  0.  0. ...,  0.  2.  0.]
 [ 0.  0.  1. ...,  1.  1.  0.]]

In [49]:
print data.mean(axis=1)


[ 5.45   5.425  6.1    5.9    5.55   6.225  5.975  6.65   6.625  6.525
  6.775  5.8    6.225  5.75   5.225  6.3    6.55   5.7    5.85   6.55
  5.775  5.825  6.175  6.1    5.8    6.425  6.05   6.025  6.175  6.55
  6.175  6.35   6.725  6.125  7.075  5.725  5.925  6.15   6.075  5.75
  5.975  5.725  6.3    5.9    6.75   5.925  7.225  6.15   5.95   6.275  5.7
  6.1    6.825  5.975  6.725  5.7    6.25   6.4    7.05   5.9  ]

In [50]:
print data.mean(axis=1).shape


(60,)

In [56]:
import matplotlib.pyplot

In [61]:
%matplotlib inline
image = matplotlib.pyplot.imshow(data)
matplotlib.pyplot.show(image)



In [62]:
print data


[[ 0.  0.  1. ...,  3.  0.  0.]
 [ 0.  1.  2. ...,  1.  0.  1.]
 [ 0.  1.  1. ...,  2.  1.  1.]
 ..., 
 [ 0.  1.  1. ...,  1.  1.  1.]
 [ 0.  0.  0. ...,  0.  2.  0.]
 [ 0.  0.  1. ...,  1.  1.  0.]]

In [63]:
print data.shape


(60, 40)

In [65]:
print data.mean(axis=0).shape


(40,)

In [66]:
print data.mean(0)


[  0.           0.45         1.11666667   1.75         2.43333333   3.15
   3.8          3.88333333   5.23333333   5.51666667   5.95         5.9
   8.35         7.73333333   8.36666667   9.5          9.58333333
  10.63333333  11.56666667  12.35        13.25        11.96666667
  11.03333333  10.16666667  10.           8.66666667   9.15         7.25
   7.33333333   6.58333333   6.06666667   5.95         5.11666667   3.6
   3.3          3.56666667   2.48333333   1.5          1.13333333
   0.56666667]

In [67]:
print data.mean(axis=0)


[  0.           0.45         1.11666667   1.75         2.43333333   3.15
   3.8          3.88333333   5.23333333   5.51666667   5.95         5.9
   8.35         7.73333333   8.36666667   9.5          9.58333333
  10.63333333  11.56666667  12.35        13.25        11.96666667
  11.03333333  10.16666667  10.           8.66666667   9.15         7.25
   7.33333333   6.58333333   6.06666667   5.95         5.11666667   3.6
   3.3          3.56666667   2.48333333   1.5          1.13333333
   0.56666667]

In [68]:
avg_inflammation = data.mean(axis=0)

In [70]:
ave_plot = matplotlib.pyplot.plot(avg_inflammation)



In [72]:
max_inflammation = data.max(axis=0)
matplotlib.pyplot.plot(max_inflammation)


Out[72]:
[<matplotlib.lines.Line2D at 0x7f14aa719e10>]

In [73]:
min_inflammation = data.min(axis=0)
matplotlib.pyplot.plot(min_inflammation)


Out[73]:
[<matplotlib.lines.Line2D at 0x7f14aa814810>]

In [75]:
import numpy
import matplotlib.pyplot

data = numpy.loadtxt(fname='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(fig)



In [ ]: