In [2]:
import numpy
In [3]:
1 + 3
Out[3]:
4
In [4]:
numpy.loadtxt(fname='data/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]:
data = numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
In [6]:
data
Out[6]:
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 [7]:
print data.min(), data.max()
0.0 20.0

In [8]:
print numpy.min(data), numpy.max(data)
0.0 20.0

In [10]:
data.median()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-40793500eb14> in <module>()
----> 1 data.median()

AttributeError: 'numpy.ndarray' object has no attribute 'median'
In [11]:
numpy.median(data)
Out[11]:
5.0
In [12]:
x = 5
y = 3
In [13]:
print x
print y
print x + y
print x * y
print x - y
print x / y
5
3
8
15
2
1

In [14]:
type(x)
Out[14]:
int
In [15]:
x = 5.0
y = 3.0
In [ ]:
d
In [16]:
print x
print y
print x + y
print x * y
print x - y
print x / y
5.0
3.0
8.0
15.0
2.0
1.66666666667

In [18]:
5.0 / 3.0
Out[18]:
1.6666666666666667
In [19]:
float(5) / float(3)
Out[19]:
1.6666666666666667
In [20]:
x = 5
y = 3
float(x)
Out[20]:
5.0
In [22]:
x = 5
y = x * 2
print x, y
5 10

In [23]:
x = x * 10
print x, y
50 10

In [24]:
data
Out[24]:
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 [25]:
%matplotlib inline
In [26]:
import matplotlib.pyplot
In [27]:
data.shape
Out[27]:
(60, 40)
In [28]:
data[0]
Out[28]:
array([  0.,   0.,   1.,   3.,   1.,   2.,   4.,   7.,   8.,   3.,   3.,
         3.,  10.,   5.,   7.,   4.,   7.,   7.,  12.,  18.,   6.,  13.,
        11.,  11.,   7.,   7.,   4.,   6.,   8.,   8.,   4.,   4.,   5.,
         7.,   3.,   4.,   2.,   3.,   0.,   0.])
In [29]:
data[1]
Out[29]:
array([  0.,   1.,   2.,   1.,   2.,   1.,   3.,   2.,   2.,   6.,  10.,
        11.,   5.,   9.,   4.,   4.,   7.,  16.,   8.,   6.,  18.,   4.,
        12.,   5.,  12.,   7.,  11.,   5.,  11.,   3.,   3.,   5.,   4.,
         4.,   5.,   5.,   1.,   1.,   0.,   1.])
In [30]:
data[59]
Out[30]:
array([  0.,   0.,   1.,   0.,   3.,   2.,   5.,   4.,   8.,   2.,   9.,
         3.,   3.,  10.,  12.,   9.,  14.,  11.,  13.,   8.,   6.,  18.,
        11.,   9.,  13.,  11.,   8.,   5.,   5.,   2.,   8.,   5.,   3.,
         5.,   4.,   1.,   3.,   1.,   1.,   0.])
In [31]:
data[60]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-31-f6eaa9bbc290> in <module>()
----> 1 data[60]

IndexError: index 60 is out of bounds for axis 0 with size 60
In [32]:
data[0]
Out[32]:
array([  0.,   0.,   1.,   3.,   1.,   2.,   4.,   7.,   8.,   3.,   3.,
         3.,  10.,   5.,   7.,   4.,   7.,   7.,  12.,  18.,   6.,  13.,
        11.,  11.,   7.,   7.,   4.,   6.,   8.,   8.,   4.,   4.,   5.,
         7.,   3.,   4.,   2.,   3.,   0.,   0.])
In [34]:
data[0, 5]
Out[34]:
2.0
In [35]:
matplotlib.pyplot.plot(data[0])
Out[35]:
[<matplotlib.lines.Line2D at 0x7f7eb511ded0>]
In [36]:
numpy.set_printoptions(linewidth=50)
In [37]:
data[0]
Out[37]:
array([  0.,   0.,   1.,   3.,   1.,   2.,   4.,
         7.,   8.,   3.,   3.,   3.,  10.,   5.,
         7.,   4.,   7.,   7.,  12.,  18.,   6.,
        13.,  11.,  11.,   7.,   7.,   4.,   6.,
         8.,   8.,   4.,   4.,   5.,   7.,   3.,
         4.,   2.,   3.,   0.,   0.])
In [38]:
s = 'reclaim'
In [39]:
type(s)
Out[39]:
str
In [40]:
for char in s:
    print char
r
e
c
l
a
i
m

In [41]:
for char in s:
    print char
    print 'x'
print 'y'
r
x
e
x
c
x
l
x
a
x
i
x
m
x
y

In [42]:
range(5)
Out[42]:
[0, 1, 2, 3, 4]
In [43]:
for i in range(5):
    print i
0
1
2
3
4

In [45]:
for i in range(60):
    patient = data[i]
    print 'patient', i, 'min value', \
        patient.min(), 'mean value', patient.mean()
 patient 0 min value 0.0 mean value 5.45
patient 1 min value 0.0 mean value 5.425
patient 2 min value 0.0 mean value 6.1
patient 3 min value 0.0 mean value 5.9
patient 4 min value 0.0 mean value 5.55
patient 5 min value 0.0 mean value 6.225
patient 6 min value 0.0 mean value 5.975
patient 7 min value 0.0 mean value 6.65
patient 8 min value 0.0 mean value 6.625
patient 9 min value 0.0 mean value 6.525
patient 10 min value 0.0 mean value 6.775
patient 11 min value 0.0 mean value 5.8
patient 12 min value 0.0 mean value 6.225
patient 13 min value 0.0 mean value 5.75
patient 14 min value 0.0 mean value 5.225
patient 15 min value 0.0 mean value 6.3
patient 16 min value 0.0 mean value 6.55
patient 17 min value 0.0 mean value 5.7
patient 18 min value 0.0 mean value 5.85
patient 19 min value 0.0 mean value 6.55
patient 20 min value 0.0 mean value 5.775
patient 21 min value 0.0 mean value 5.825
patient 22 min value 0.0 mean value 6.175
patient 23 min value 0.0 mean value 6.1
patient 24 min value 0.0 mean value 5.8
patient 25 min value 0.0 mean value 6.425
patient 26 min value 0.0 mean value 6.05
patient 27 min value 0.0 mean value 6.025
patient 28 min value 0.0 mean value 6.175
patient 29 min value 0.0 mean value 6.55
patient 30 min value 0.0 mean value 6.175
patient 31 min value 0.0 mean value 6.35
patient 32 min value 0.0 mean value 6.725
patient 33 min value 0.0 mean value 6.125
patient 34 min value 0.0 mean value 7.075
patient 35 min value 0.0 mean value 5.725
patient 36 min value 0.0 mean value 5.925
patient 37 min value 0.0 mean value 6.15
patient 38 min value 0.0 mean value 6.075
patient 39 min value 0.0 mean value 5.75
patient 40 min value 0.0 mean value 5.975
patient 41 min value 0.0 mean value 5.725
patient 42 min value 0.0 mean value 6.3
patient 43 min value 0.0 mean value 5.9
patient 44 min value 0.0 mean value 6.75
patient 45 min value 0.0 mean value 5.925
patient 46 min value 0.0 mean value 7.225
patient 47 min value 0.0 mean value 6.15
patient 48 min value 0.0 mean value 5.95
patient 49 min value 0.0 mean value 6.275
patient 50 min value 0.0 mean value 5.7
patient 51 min value 0.0 mean value 6.1
patient 52 min value 0.0 mean value 6.825
patient 53 min value 0.0 mean value 5.975
patient 54 min value 0.0 mean value 6.725
patient 55 min value 0.0 mean value 5.7
patient 56 min value 0.0 mean value 6.25
patient 57 min value 0.0 mean value 6.4
patient 58 min value 0.0 mean value 7.05
patient 59 min value 0.0 mean value 5.9

In [46]:
for i in range(2):
    patient = data[i]
    matplotlib.pyplot.plot(patient)
In [47]:
data.min(axis=0)
Out[47]:
array([ 0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,
        2.,  2.,  2.,  2.,  3.,  3.,  3.,  3.,
        4.,  5.,  5.,  5.,  5.,  4.,  4.,  4.,
        4.,  3.,  3.,  3.,  3.,  2.,  2.,  2.,
        2.,  1.,  1.,  1.,  1.,  0.,  0.,  0.])
In [48]:
data.min(axis=0).shape
Out[48]:
(40,)
In [54]:
f = matplotlib.pyplot.figure()
plot1 = f.add_subplot(2, 1, 1)
plot2 = f.add_subplot(2, 1, 2)
plot1.plot(data.mean(axis=0))
plot2.plot(data.max(axis=0))
plot1.set_ylabel('mean')
plot2.set_ylabel('maximum')
Out[54]:
<matplotlib.text.Text at 0x7f7eb4b7e250>
In [67]:
for i in range(3):
    patient = data[i]
    f = matplotlib.pyplot.figure()
    mango = f.add_subplot(1, 1, 1)
    # the next line actually does the plotting!
    mango.plot(patient)
    mango.set_title('patient ' + str(i))

s

In [58]:
print s[0], s[1], s[len(s)-1]
r e m

In [59]:
print s[-1], s[-2], s[-len(s)]
m i r

In [60]:
s[1:5]
Out[60]:
'ecla'
In [61]:
5 - 1
Out[61]:
4
In [62]:
len(s)
Out[62]:
7
In [68]:
s = 'abcdefghijkl'
In [69]:
s[0:5]
Out[69]:
'abcde'
In [70]:
s[0:5:2]
Out[70]:
'ace'
In [74]:
s[::]
Out[74]:
'abcdefghijkl'
In [75]:
s[1:-1]
Out[75]:
'bcdefghijk'
In [76]:
# Print the string reverse, e.g.'lkjihgfedcba'
# Hint: the "step" can also be negative
In [77]:
s[::-1]
Out[77]:
'lkjihgfedcba'
In [83]:
s[-1::-1]
Out[83]:
'lkjihgfedcba'
In [84]:
s[0:len(s):1]
Out[84]:
'abcdefghijkl'
In [85]:
data
Out[85]:
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 [87]:
data[3:5, 1:4]
Out[87]:
array([[ 0.,  2.,  0.],
       [ 1.,  1.,  3.]])
In [88]:
data[1:-1, 1:-1]
Out[88]:
array([[ 1.,  2.,  1., ...,  1.,  1.,  0.],
       [ 1.,  1.,  3., ...,  2.,  2.,  1.],
       [ 0.,  2.,  0., ...,  2.,  3.,  2.],
       ..., 
       [ 1.,  1.,  2., ...,  2.,  2.,  1.],
       [ 1.,  1.,  1., ...,  2.,  1.,  1.],
       [ 0.,  0.,  1., ...,  2.,  0.,  2.]])
In [89]:
data[1:-1, 1:-1].shape
Out[89]:
(58, 38)
In [90]:
data[:3, :3]
Out[90]:
array([[ 0.,  0.,  1.],
       [ 0.,  1.,  2.],
       [ 0.,  1.,  1.]])
In [91]:
data[0]
Out[91]:
array([  0.,   0.,   1.,   3.,   1.,   2.,   4.,
         7.,   8.,   3.,   3.,   3.,  10.,   5.,
         7.,   4.,   7.,   7.,  12.,  18.,   6.,
        13.,  11.,  11.,   7.,   7.,   4.,   6.,
         8.,   8.,   4.,   4.,   5.,   7.,   3.,
         4.,   2.,   3.,   0.,   0.])
In [92]:
data[:, 0]
Out[92]:
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.,  0.])
In [93]:
# Print out the average for all 40 time points (columns)
# E.g.
#    day 0: 0.0
#    day 1: 1.2
#    ...
#    day 39: 0.2
In [94]:
range(40)
Out[94]:
[0,
 1,
 2,
 3,
 4,
 5,
 6,
 7,
 8,
 9,
 10,
 11,
 12,
 13,
 14,
 15,
 16,
 17,
 18,
 19,
 20,
 21,
 22,
 23,
 24,
 25,
 26,
 27,
 28,
 29,
 30,
 31,
 32,
 33,
 34,
 35,
 36,
 37,
 38,
 39]
In [96]:
for i in range(5):
    print 'day', i, ':', data[:, i].mean()
day 0 : 0.0
day 1 : 0.45
day 2 : 1.11666666667
day 3 : 1.75
day 4 : 2.43333333333

In [97]:
range(5)
Out[97]:
[0, 1, 2, 3, 4]
In [98]:
[0, 1, 2, 3, 4]
Out[98]:
[0, 1, 2, 3, 4]
In [99]:
[0, 1, 'string', 4.5, numpy]
Out[99]:
[0,
 1,
 'string',
 4.5,
 <module 'numpy' from '/usr/lib64/python2.7/site-packages/numpy/__init__.pyc'>]
In [100]:
x = range(5)
In [101]:
x[0]
Out[101]:
0
In [102]:
x[-1]
Out[102]:
4
In [103]:
x[::2]
Out[103]:
[0, 2, 4]
In [104]:
x[::-1]
Out[104]:
[4, 3, 2, 1, 0]
In [105]:
x = 5
x = 6
In [106]:
x
Out[106]:
6
In [107]:
y = x
In [108]:
y
Out[108]:
6
In [109]:
x = 11
In [110]:
L = range(5)
In [111]:
L
Out[111]:
[0, 1, 2, 3, 4]
In [112]:
L[1] = 'x'
In [113]:
L
Out[113]:
[0, 'x', 2, 3, 4]
In [114]:
L.append(5)
In [115]:
L
Out[115]:
[0, 'x', 2, 3, 4, 5]
In [116]:
L2 = L
In [117]:
print L, L2
[0, 'x', 2, 3, 4, 5] [0, 'x', 2, 3, 4, 5]

In [118]:
L[3] = 11
In [119]:
print L, L2
[0, 'x', 2, 11, 4, 5] [0, 'x', 2, 11, 4, 5]

In [120]:
s
Out[120]:
'abcdefghijkl'
In [121]:
s[1] = 'x'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-121-1e217d0fd24e> in <module>()
----> 1 s[1] = 'x'

TypeError: 'str' object does not support item assignment
In [122]:
import glob
In [123]:
glob.glob('data/small-*.csv')
Out[123]:
['data/small-02.csv', 'data/small-01.csv', 'data/small-03.csv']
In [124]:
files = glob.glob('data/small-*.csv')
In [125]:
files[0]
Out[125]:
'data/small-02.csv'
In [126]:
# opening files:
#  numpy.loadtxt(fname='data/inflammation-01.csv', delimiter=',')
# loops:
#  for fname in files:
#    ...
# glob
# data.shape

# Print the size (the shape) of each file
# from data/inflammation*.csv
In [133]:
files = glob.glob('data/inf*csv')
files
Out[133]:
['data/inflammation-12.csv',
 'data/inflammation-01.csv',
 'data/inflammation-05.csv',
 'data/inflammation-08.csv',
 'data/inflammation-04.csv',
 'data/inflammation-02.csv',
 'data/inflammation-06.csv',
 'data/inflammation-11.csv',
 'data/inflammation-10.csv',
 'data/inflammation-09.csv',
 'data/inflammation-07.csv',
 'data/inflammation-03.csv']
In [134]:
for fname in files:
    data = numpy.loadtxt(fname=fname, delimiter=',')
    print fname, data.shape
data/inflammation-12.csv (60, 40)
data/inflammation-01.csv (60, 40)
data/inflammation-05.csv (60, 40)
data/inflammation-08.csv (60, 40)
data/inflammation-04.csv (60, 40)
data/inflammation-02.csv (60, 40)
data/inflammation-06.csv (60, 40)
data/inflammation-11.csv (60, 40)
data/inflammation-10.csv (60, 40)
data/inflammation-09.csv (60, 40)
data/inflammation-07.csv (60, 40)
data/inflammation-03.csv (60, 40)

In [135]:
data
Out[135]:
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  1.,  0.,  0.],
       [ 0.,  0.,  1., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  0.,  1., ...,  1.,  0.,  0.],
       [ 0.,  0.,  1., ...,  1.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]])
In [136]:
matplotlib.pyplot.imshow(data)
Out[136]:
<matplotlib.image.AxesImage at 0x7f7eb43e84d0>
In [137]:
len(12)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-137-954f5ceb39e6> in <module>()
----> 1 len(12)

TypeError: object of type 'int' has no len()
In [138]:
len(files)
Out[138]:
12
In [ ]:
# Plot 12 colormaps for 12 files

matplotlib.pyplot.imshow(data)
In [139]:
f = matplotlib.pyplot.figure()
for i in range(3):
    for j in range(4):
        f.add_subplot(3, 4, i*4 + j)
In [142]:
datas = []
for fname in files:
    data = numpy.loadtxt(fname=fname, delimiter=',')
    # print fname, data.shape
    datas.append(data)
In [141]:
len(datas)
Out[141]:
12
In [147]:
f = matplotlib.pyplot.figure()
for i in range(3):
    for j in range(4):
        num = i*4 + j
        subplot = f.add_subplot(3, 4, 1 + num)
        subplot.set_title(str(num))
        data = datas[num]
        subplot.imshow(data)
        
f.tight_layout()
In [169]:
def fahr_to_celcius(temp):
    return (temp - 32) * float(5)/9
In [170]:
fahr_to_celcius(0)
Out[170]:
-17.77777777777778
In [171]:
fahr_to_celcius(98.)
Out[171]:
36.666666666666664
In [172]:
fahr_to_celcius(98)
Out[172]:
36.666666666666664
In [173]:
def celcius_to_kelvin(temp):
    return 273 + temp
In [175]:
celcius_to_kelvin(100)
Out[175]:
373
In [176]:
def fahr_to_kelvin(temp):
    x = fahr_to_celcius(temp)
    return celcius_to_kelvin(x)
In [177]:
fahr_to_kelvin(98)
Out[177]:
309.6666666666667
In [185]:
def plot_data(subplot, plot_number, data):
    print subplot, plot_number, data.shape
    subplot.imshow(data)
    subplot.set_title(str(plot_number))
    subplot.set_ylabel('patient')
    subplot.set_xlabel('time')
In [186]:
f = matplotlib.pyplot.figure()
for i in range(3):
    for j in range(4):
        num = i*4 + j
        subplot = f.add_subplot(3, 4, 1 + num)
        data = datas[num]
        plot_data(subplot, num, data)
        
f.tight_layout()
Axes(0.125,0.672059;0.168478x0.227941) 0 (60, 40)
Axes(0.327174,0.672059;0.168478x0.227941) 1 (60, 40)
Axes(0.529348,0.672059;0.168478x0.227941) 2 (60, 40)
Axes(0.731522,0.672059;0.168478x0.227941) 3 (60, 40)
Axes(0.125,0.398529;0.168478x0.227941) 4 (60, 40)
Axes(0.327174,0.398529;0.168478x0.227941) 5 (60, 40)
Axes(0.529348,0.398529;0.168478x0.227941) 6 (60, 40)
Axes(0.731522,0.398529;0.168478x0.227941) 7 (60, 40)
Axes(0.125,0.125;0.168478x0.227941) 8 (60, 40)
Axes(0.327174,0.125;0.168478x0.227941) 9 (60, 40)
Axes(0.529348,0.125;0.168478x0.227941) 10 (60, 40)
Axes(0.731522,0.125;0.168478x0.227941) 11 (60, 40)

In [187]:
def plot_many_patients(datas):
    f = matplotlib.pyplot.figure()
    for i in range(3):
        for j in range(4):
            num = i*4 + j
            subplot = f.add_subplot(3, 4, 1 + num)
            data = datas[num]
            plot_data(subplot, num, data)
        
    f.tight_layout()
In [188]:
plot_many_patients(datas)
Axes(0.125,0.672059;0.168478x0.227941) 0 (60, 40)
Axes(0.327174,0.672059;0.168478x0.227941) 1 (60, 40)
Axes(0.529348,0.672059;0.168478x0.227941) 2 (60, 40)
Axes(0.731522,0.672059;0.168478x0.227941) 3 (60, 40)
Axes(0.125,0.398529;0.168478x0.227941) 4 (60, 40)
Axes(0.327174,0.398529;0.168478x0.227941) 5 (60, 40)
Axes(0.529348,0.398529;0.168478x0.227941) 6 (60, 40)
Axes(0.731522,0.398529;0.168478x0.227941) 7 (60, 40)
Axes(0.125,0.125;0.168478x0.227941) 8 (60, 40)
Axes(0.327174,0.125;0.168478x0.227941) 9 (60, 40)
Axes(0.529348,0.125;0.168478x0.227941) 10 (60, 40)
Axes(0.731522,0.125;0.168478x0.227941) 11 (60, 40)

In [191]:
def f(x, y, z):
    print x, y, z

f(x=1, z=3, y=2, )
1 2 3

In [193]:
def f(x, y, z=5):
    print x, y, z
    
f(1, 2, 3)
f(x=1, y=2, z=3)
f(1, 2)
1 2 3
1 2 3
1 2 5

In [196]:
x = 5
if x == 5:
    print 'x is 5'
else:
    print 'x is not 5'
x is 5

In [198]:
x = 6
if x == 5:
    print 'x is 5'
In [201]:
# Write a function which prints the min, max, and median
# of data
# if requested
#
def print_info(data, show_min=1, show_max=1, show_median=1):
    print '?'
In [202]:
print_info(data, 1, 1, 0)
?

In [207]:
def print_info(data, show_min=1, show_max=1, show_median=1):
    if show_min == 1:
        print 'min', data.min()
    if show_max == 1:
        print 'max', data.max()
    if show_median == 1:
        print 'median', numpy.median(data)
In [208]:
print_info(data, 1, 1, 0)
min 0.0
max 20.0

In [209]:
print_info(data, 0, 0, 0)
In [210]:
print_info(data, show_min=0, show_max=0, show_median=1)
median 3.0

In [212]:
if x:
    print 'x is true'
x is true

In [219]:
print bool(0), bool(1)
False True

In [220]:
print bool(0.0), bool(0.1)
False True

In [221]:
L
Out[221]:
[0, 'x', 2, 11, 4, 5]
In [222]:
bool(L)
Out[222]:
True
In [225]:
print bool([1]), bool([])
True False

In [226]:
bool([0])
Out[226]:
True
In [227]:
bool(True)
Out[227]:
True
In [228]:
bool(False)
Out[228]:
False
In [230]:
bool(None)
Out[230]:
False
In [231]:
def print_info(data, show_min=True, show_max=True,
                     show_median=True):
    if show_min:
        print 'min', data.min()
    if show_max:
        print 'max', data.max()
    if show_median:
        print 'median', numpy.median(data)
In [ ]:
# Things that are false:
# 1. zeros and False
# 2. empty lists and other sequences
# 3. None