-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathlecture03.tex
1537 lines (1434 loc) · 46.8 KB
/
lecture03.tex
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[10pt]{beamer}
\usetheme{metropolis}
\usepackage{appendixnumberbeamer}
\usepackage{booktabs}
\usepackage[scale=2]{ccicons}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usepackage{xspace}
\usepackage{tikz}
\usetikzlibrary{positioning}
%\usepackage{listings}
\usepackage{minted}
\usepackage{bm}%................................. Bold math symbols (after fonts)
\setbeamercolor{normal text}{bg=white}
\title{EML4930/EML6934: Lecture 03}
\subtitle{Objects, Namespace, Python libraries, and pip}
\date{September 14, 2017}
%\author{CJ}
\author{Charles Jekel}
%\titlegraphic{\includegraphics{images/avatarCropped.png}\vspace{58cm}}
%\institute{1. University of Florida\\ 2. Stellenbosch University, South Africa}
% \titlegraphic{\hfill\includegraphics[height=1.5cm]{logo.pdf}}
\begin{document}
\maketitle
\begin{frame}[fragile]{Objects - everything in Python is an object}
In this example x isn't really a string. It is an object containing a collection of functions
\begin{minted}
{python}
in : x = 'hello world'
in : dir(x)
\end{minted}
dir(object) returns an alphabetized list of the attributes of the object
\end{frame}
\begin{frame}{Object Oriented Programming - OOP}
\begin{alertblock}{Object Oriented Programming}
A programming paradigm in which code related to a particular \textit{object} is grouped together.
\end{alertblock}
\begin{itemize}
\item Class - the \textbf{definition} of an Object
\item Object - an \textbf{instance} of a Class
\item Everything in Python is an object
\item Advantage - less duplicate code
\item Disadvantage - performance issues with OOP
\end{itemize}
\end{frame}
\begin{frame}{Objects and dogs...}
Imagine you had to write a veterinarian program about dogs. What functions and attributes would all dogs have in common?
\begin{figure}
\includegraphics[width=1.0\textwidth]{figs/dog.jpg}
\end{figure}
\end{frame}
\begin{frame}[fragile]{Use class to create a new form of object}
Some reading: \url{https://docs.python.org/3/tutorial/classes.html} \url{http://anandology.com/python-practice-book/object_oriented_programming.html}
I like this idea of creating a bank account to explain how to use class.
\end{frame}
\begin{frame}[fragile]{Creating a bank account object}
\begin{minted}
{python}
class bank_account:
def __init__(self, initial_balance=0.0):
self.balance = initial_balance
john = bank_account()
\end{minted}
\begin{itemize}
\item use class to create an object named bank\_account
\item def \_\_init\_\_() is an initialization function that is run automatically on a new instance
\item you can add required and optional variables to the \_\_init\_\_() function
\item self is the naming convention in python of objects own instance (it's self)
\item self is the first variable in your functions of your object
\item pass self to your object's functions if you need access to your object's attributes\
\item balance is an attribute of the object
\item a new instance of the object is created by calling bank\_account()
\end{itemize}
\end{frame}
\begin{frame}[fragile]{adding a withdrawn and deposit function}
\begin{minted}
{python}
class bank_account:
def __init__(self, initial_balance=0.0):
self.balance = initial_balance
def withdraw(self, ammount):
self.balance -= ammount
print('Your new account balance is', self.balance)
def deposit(self, ammount):
self.balance += ammount
print('Your new account balance is', self.balance)
\end{minted}
\begin{minted}
{python}
in : john = bank_account(100.0)
in : john.withdraw(2.77)
out: Your new account balance is 97.23
in : john.deposit(10.0)
out: Your new account balance is 107.23
\end{minted}
\end{frame}
\begin{frame}[fragile]{Adding extra attribute - liability and loan}
\begin{minted}
{python}
class bank_account:
def __init__(self, initial_balance=0.0, initial_debt=0.0):
self.balance = initial_balance; self.debt = initial_debt
def withdraw(self, ammount):
self.balance -= ammount; self.print_balance()
def deposit(self, ammount):
self.balance += ammount; self.print_balance()
def get_loan(self, ammount):
self.balance += ammount; self.debt += ammount
self.print_balance()
def pay_debt(self, ammount):
self.balance -= ammount; self.debt -= ammount
self.print_balance()
def print_balance(self):
print('Your account balance is', self.balance,
'\n You own the bank', self.debt)
\end{minted}
\end{frame}
\begin{frame}[fragile]{Playing arround with the newly created object}
\begin{minted}
{python}
in : john = bank_account(100.0,10)
in : john.withdraw(2.77)
out: Your account balance is 97.23
You own the bank 10
in : john.deposit(10.00)
out: Your account balance is 107.23
You own the bank 10
in : john.get_loan(1000.0)
out: Your account balance is 1107.23
You own the bank 1010.0
in : john.pay_debt(723.0)
out: Your account balance is 384.23
You own the bank 287.0
\end{minted}
\end{frame}
\begin{frame}[fragile]{Objects are incredibly useful}
\begin{itemize}
\item I have no idea how people created large programs before object oriented programming
\item You can use objects to organize a collection of functions
\item Use dir() to see all of the attributes of an object
\item Python naming convention object\_instance.attribute
\item attributes can be new data types, data structures, and even new objects
\item \textbf{.} is used to access the object's attributes
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Custom rich comparisons for your object}
Here I define custom rich comparisons for my object, which only compares the attribute x of the object.
\begin{minted}
{python}
def __lt__(self, other) # <
return self.x < other.x
def __le__(self, other) # <=
return self.x < other.x
def __eq__(self, other) # ==
return self.x < other.x
def __ne__(self, other) # !=
return self.x < other.x
def __gt__(self, other) # >
return self.x < other.x
def __ge__(self, other) # >=
return self.x < other.x
\end{minted}
\end{frame}
\begin{frame}{Objects summary}
\begin{itemize}
\item class defines an object
\item def \_\_init\_\_ is a function that runs upon the initialization of an object
\item dir(object) displays the attributes of an object
\item \_\_eq\_\_ defines equality for your object
\item You can define custom comparisons for your objects
\end{itemize}
\end{frame}
\begin{frame}{Python Namespace}
The namespace in Python is a system to make sure that all the names in a program are unique and can be used without conflict. Namespace is a way to implement scope.
\url{https://www.programiz.com/python-programming/namespace}
\begin{figure}
\includegraphics[width=0.65\textwidth]{figs/-namespaces-python.jpg}
\end{figure}
\end{frame}
\begin{frame}[fragile]{An example of name space - dir() shows us the active names or attributes}
\begin{minted}
{python}
a = 2.0
def outter_fun():
b = 3.0
def inner_fun():
c = 3.0
print('inner function', dir())
inner_fun()
print('outter function', dir())
outter_fun()
print('script space', dir())
\end{minted}
\end{frame}
\begin{frame}[fragile]{Functions and namespace}
\begin{minted}
{python}
x = 2.0
def print_x_new():
x = 1.0
print(x)
print_x_new()
\end{minted}
Does this code change x?
\end{frame}
\begin{frame}[fragile]{Functions and namespace - global}
\begin{minted}
{python}
x = 2.0
def print_x_new():
global x
x = 1.0
print(x)
print_x_new()
\end{minted}
Does this code change x?
You need to declare \textit{global} before variable assignment
\end{frame}
\begin{frame}{Namespaces in Python is a good idea}
\url{http://pclib.github.io/safari/program/learning-python/Text/ch29s04.html}
Some good reading with Namespaces and Python.
There is much to discuss but little time.
I recommended taking a look at the source code of how a library you use is organized. Such as numpy \url{https://github.com/numpy/numpy/tree/master/numpy}
\end{frame}
\begin{frame}{Python standard libraries}
\url{https://docs.python.org/3/library/index.html}
The Python libraries available with any Python installation.
\begin{itemize}
\item math - Mathematical function
\item cmath - Mathematical functions for complex numbers
\item itertools - functions for creating iterators for efficient looping
\item pickle - Python object serialization (storing objects)
\item csv - csv file read and write
\item os - miscellaneous operating system interface
\item and many more!
\end{itemize}
\end{frame}
\begin{frame}{Special Python libraries we'll use in this course}
\begin{itemize}
\item numpy - fundamental package for scientific computing with Python
\item matplotlib - Python 2D plotting library
\item scipy - Python-based ecosystem of open-source software for mathematics, science, and engineering
\item sympy - symbolic math with Python
\item sklearn - scikit-learn machine learning in Python
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Libraries and namespace - basic import}
\begin{minted}
{python}
import math
math.cos(math.pi)
\end{minted}
\begin{itemize}
\item explicit import of the math library
\item this is the most recommended type of import
\item the functions of the math library exist in the math namespace
\item run dir(math) to view all of the functions
\item you access the functions using .
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Libraries and namespace - import as alias}
\begin{minted}
{python}
import numpy as np
np.cos(np.pi)
\end{minted}
\begin{itemize}
\item sometimes it's inconvient to use the entire name of a library
\item in this example we assign an alias np using as
\item use the convention when importing libraries
\item it is the convention to import numpy as np
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Libraries and namespace - explicit import of specific functions}
\begin{minted}
{python}
from math import cos, pi
cos(pi)
\end{minted}
\begin{itemize}
\item sometimes it is useful to import just a few functions of a library
\item in this case there will be no math namespace
\item instead the functions cos and pi will occur in the local namespace
\item from library import function1, function2, function3
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Libraries and namespace - implicit import of all functions}
\begin{minted}
{python}
from sympy import *
\end{minted}
\begin{itemize}
\item this imports all of the functions of sympy into the local namespace
\item if this isn't officially recommended by your library, it could break default Python functions
\item for instance from numpy import * would override max() and min() functions with the numpy max() and min() functions
\end{itemize}
\end{frame}
\begin{frame}[fragile]{import os - useful for importing your operating system functions}
\begin{minted}
{python}
import os
os.getcwd() # returns the current working directory as a string
os.chdir(path) # changes the working directory to path
os.listdir() # returns a list of the entries in the current directory
os.listdir(path)# a list of the entries in the path directory
os.system() # lets you run commands from your system terminal/prompt
'''
os.system(command)
Execute the command in a subshell.
'''
\end{minted}
\end{frame}
\begin{frame}[fragile]{The PyPA recommended tool for installing Python packages}
pip is a tool for installing python packages -- execute pip from the anaconda prompt/terminal or the canopy prompt/terminal
\url{https://pip.pypa.io/en/stable/quickstart/}
Install a package:
\begin{minted}
{bash}
$ pip install numpy
\end{minted}
Upgrade a package:
\begin{minted}
{bash}
$ pip install --upgrade numpy
\end{minted}
Upgrade pip:
\begin{minted}
{bash}
$ pip install --upgrade pip
\end{minted}
List what packages are outdated:
\begin{minted}
{bash}
$ pip list --outdated
\end{minted}
\end{frame}
\begin{frame}[fragile]{conda - if you installed Anaconda}
conda is part of the Anaconda distribution and is a package, dependency manager for multiple languages \url{https://conda.io/docs/}
You access conda from the Anaconda prompt/terminal
To install a package:
\begin{minted}
{bash}
$ conda install <package-name>
\end{minted}
To list the packages you have installed:
\begin{minted}
{bash}
$ conda list
\end{minted}
To update all packages:
\begin{minted}
{bash}
$ conda update --all
\end{minted}
To list all packages that are available
\begin{minted}
{bash}
$ conda search
\end{minted}
\end{frame}
\begin{frame}[fragile]{HW 03 - turn in one week from today in Canvas}
Turn in the 5 questions as a single .py file onto canvas. Use comments to clearly indicate which question you are working on. Your filename should end as \_py2.py if you use Python2 and \_py3.py if you use Python3.
\begin{enumerate}
%\setcounter{enumi}{5}
\item Open an Anaconda/Canopy prompt/terminal. Enter the command \textit{pip install pydoe} or (\textit{conda install pydoe} if you've installed anaconda) to install the pydoe package. This is a Python Design of Experiments library. In your .py file import pyDOE.
\item Use the os library to print the current Python working directory. It is very useful to run system commands using os.system(). Import os. Run a system command to use the system's \textit{ping} program. If you are using Windows run the command \textit{ping -n 2 ufl.edu} or if you are using Linux/OS \textit{ping -c 2 ufl.edu}. Hint: your command should be a string in Python.
\item Compare math.pi to numpy.pi. Are these two representations of $\pi$ equivalent? Print the boolean statement True if they are, otherwise print False.
\end{enumerate}
\end{frame}
\begin{frame}[fragile]{HW 03 - turn in one week from today in Canvas}
\begin{enumerate}
\setcounter{enumi}{3}
\item Create a class called sphere. The object sphere requires a radius and mass to initialize. The attributes of the sphere should include the radius ($r$), mass ($m$), volume ($v$), surface area ($A$), and density ($\rho$). Initiate a new sphere name red with $r=1.7$ and $m=0.25$. Print dir(red). Print the volume, surface area, and density of red.
\end{enumerate}
\end{frame}
\begin{frame}[fragile]{HW 03 - turn in one week from today in Canvas}
\begin{enumerate}
\setcounter{enumi}{4}
\item The Python 3 print function adds some incredibly useful functionality
\begin{minted}
{python}
x = 1.0; y = 2.0;
print(x,y,sep = ' & ')
\end{minted}
will print \textit{1.0 \& 2.0}
Given x
\begin{minted}
{python}
x = [[ 0, 1, 2, 3],[ 4, 5, 6, 7],
[ 8, 9, 10, 11],[12, 13, 14, 15]]
\end{minted}
Use a for loop to iterate through the four lists in x. Each item in the list should be printed and separated by an \&. The following should be the output of your print.
0 \& 1 \& 2 \& 3
4 \& 5 \& 6 \& 7
8 \& 9 \& 10 \& 11
12 \& 13 \& 14 \& 15
\end{enumerate}
Hint: from \_\_future\_\_ should go at the top of your script if you are using Python 2.
\end{frame}
%\begin{frame}[fragile]{HW 02 - turn in one week from today in Canvas}
%\begin{enumerate}
%\setcounter{enumi}{3}
%\item Use a loop to find the largest integer that when squared is less than 2000. Print the integer.
%\item Create a class called sphere. The object sphere requires a radius and mass to initialize. The attributes of the sphere should include the radius ($r$), mass ($m$), volume ($v$), surface area ($A$), and density ($\rho$). Initiate a new sphere name red. Print dir(red). Print the volume, surface area, and density of red.
%
%\begin{align}
%v &= \frac{4}{3}\pi r^3 \\
%A &= 4 \pi r^2 \\
%\rho &= \frac{m}{v}
%\end{align}
%\end{enumerate}
%\end{frame}
%\begin{frame}[fragile]{HW 01 - turn in one week from today in Canvas}
%\begin{enumerate}
%\setcounter{enumi}{5}
%\item The Fibonacci sequence is defined as
%\begin{equation}
%F_n = F_{n-1} + F_{n-2}
%\end{equation}
%where $n$ denotes the $n^\text{th}$ item of the Fibonacci sequence. You are given the first three numbers of the Fibonacci sequence as F = [0, 1, 1]. Create a for loop to determine the next 20 numbers of the Fibonacci sequence. Print F with the final 23 numbers. Hint: use F.append() to add a new Fibonacci value to the end of the list F.
%\item Parentheses are used to preserve order of operations in Python. The following code will add x+y first, then raise to the power z. This value is assigned g.
%\begin{minted}
%{python}
%g = (x+y)**z
%\end{minted}
%Given the list x = [2.0,3.0,5.0,7.0,9.0], create a list $Y(x)$ for each float in x. Print the list $Y$.
%\begin{equation}
%Y(x) = \frac{(3.0x)^2}{(99x - x^3)} - \frac{1}{x}
%\end{equation}
%\end{enumerate}
%
%\end{frame}
%\begin{frame}[fragile]{Creating lists with range (Python2 only)}
%\textbf{Note}: Python 3.5 changed how range works, range no longer creates lists, it is an iterable. We won't use range for numerical work, we'll use a numpy function instead.
%
%Let's use the range function to create lists of integers. How do we view the docstring of range?
%
%\begin{minted}
%{python}
%print(range.__doc__)
%\end{minted}
%
%range(stop) $->$ list of integers
%range(start, stop[, step]) $->$ list of integers
%
%Return a list containing an arithmetic progression of integers.
%range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
%When step is given, it specifies the increment (or decrement).
%For example, range(4) returns [0, 1, 2, 3]. The end point is omitted!
%These are exactly the valid indices for a list of 4 elements.
%\end{frame}
%\begin{frame}{Results from the first HW}
%\begin{figure}
% \includegraphics[width=1.0\textwidth]{figs/1.png}
%\end{figure}
%\begin{figure}
% \includegraphics[width=1.0\textwidth]{figs/2.png}
%\end{figure}
%
%\end{frame}
%
%\begin{frame}{The operating systems used by the class}
%\begin{figure}
% \includegraphics[width=1.0\textwidth]{figs/3.png}
%\end{figure}
%\end{frame}
%
%\begin{frame}{Textbook for this lecture}
%A whirlwind Tour of Python by Dr. VanderPlas is a short book to prepare users with the bare essentials
%for working with Python.
%
%It is also available for free at
% \url{http://www.oreilly.com/programming/free/files/a-whirlwind-tour-of-python.pdf}
%
% or \url{https://github.com/jakevdp/WhirlwindTourOfPython}
%
%\end{frame}
%
%\begin{frame}[fragile]{Comments}
%\begin{minted}
%{python}
%# This is a comment in Python
%
%'''
%This is a bulk comment in python
%
%Any line between the start and the end
%
%is part of the comment
%'''
%
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{Assigning variables}
%\begin{minted}
%{python}
%# Variables can be easily assigned
%# this code assigns integer 10 to x
%x = 10
%
%\end{minted}
%This officially defines a pointer named x that points to the integer 10. We can change what x points to at any time.
%\begin{minted}
%{python}
%x = 10 # x is the integer 10
%x = 10. # x is the floating point EEE-754 double precision
%x = 10.0 # same as x = 10.
%x = 'ten' # x is now a string
%x = (0,1,2) # x is now a tuple
%x = [0,1,2] # x is now a list
%x = 1; y = 2; z = 3 # assigns x = 1, y = 2, and z = 3
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{Demo - Consequences of pointers}
%\textbf{Be careful.}
%\begin{minted}
%{python}
%x = [1,2,3]
%y = x
%x[0] = 4
%print(y)
%\end{minted}
%
%\textbf{Numpy warning!}
%\begin{minted}
%{python}
%import numpy as np
%x = np.array([10])
%y = x
%x += 5
%print(y)
%# this doesn't happen if I used x = x + 5
%# this doesn't happen if x = 10 (instead of np.array([10]))
%\end{minted}
%\end{frame}
%
%\begin{frame}{Math operators}
%\begin{table}
%\begin{tabular}{lll}
%\textbf{Operater} & \textbf{Name} & \textbf{Description} \\
%\hline
%a + b & Addition & Sum of a and b \\
%a - b & Subtraction & Difference of a and b \\
%a * b & Multiplication & Product of a and b \\
%a / b & True division & Quotient of a and b \\
%a // b & Floor division & Quotient of a and b , removing fractional parts \\
%a \% b & Modulus & Remainder after division of a by b \\
%a ** b & Exponentiation & a raised to the power of b \\
%-a & Negation & The negative of a \\
%+a & Unary & plus a unchanged (rarely used) \\
%\end{tabular}
%\end{table}
%
%Page 18 of A Whirlwind Tour of Python by VanderPlas.
%\end{frame}
%
%\begin{frame}[fragile]{Division in Python2}
%Let's take a look at division in Python2
%\begin{minted}
%{python}
%a = 3
%b = 2
%c = a/b
%\end{minted}
%So we have integer a divided by integer b and I'm familiar with programming so I expect c to be an integer.
%\end{frame}
%
%\begin{frame}[fragile]{Python3 \textit{broke} division!}
%or \textit{Fixed} it, because in Python3 an integer divided by an integer magically becomes a float. Remember that import future command? We can use it to get Python3 division in Python2.
%\begin{minted}
%{python}
%from __future__ import division
%a = 3
%b = 2
%c = a/b
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{Built in data types}
%Here are the built in data types for Python. Use
%\begin{minted}
%{python}
%type(x)
%\end{minted}
%
%to display the data type of x.
%\begin{table}
%\begin{tabular}{lll}
%\textbf{Type} & \textbf{Example} & \textbf{Description} \\
%\hline
%int & x = 1 & Integers (i.e., whole numbers) \\
%float & x = 1.0 & Floating-point numbers (i.e., real numbers) \\
%complex & x = 1 + 2j & Complex numbers \\
%bool & x = True & Boolean: True/False values \\
%str & x = 'abc' & String: characters or text \\
%NoneType & x = None & Special object indicating nulls \\
%\end{tabular}
%\end{table}
%str(x) converts x to a string
%int(x) converts x to an integer
%float(x) converts x to a floating point
%
%Page 24 of A Whirlwind Tour of Python by VanderPlas.
%\end{frame}
%
%
%\begin{frame}[fragile]{Comparison operators}
%Comparison operators will return a boolean
%\begin{minted}
%{python}
%True
%False
%\end{minted}
%\begin{table}
%\begin{tabular}{ll}
%\textbf{Operation} & \textbf{Description} \\
%\hline
%a == b & a equal to b \\
%a != b & a not equal to b \\
%a $<$ b & a less than b \\
%a $>$ b & a greater than b \\
%a $<=$ b & a less than or equal to b \\
%a $>=$ b & a greater than or equal to b \\
%\end{tabular}
%\end{table}
%Page 21 of A Whirlwind Tour of Python by VanderPlas.
%\end{frame}
%
%\begin{frame}[fragile]{Floating point precision}
%\begin{minted}
%{python}
%0.1+0.2 == 0.3
%\end{minted}
%this returns False! Why?
%
%You can use the numpy isclose function to set a tolerance for floating point comparison.
%\end{frame}
%
%\begin{frame}{Data Structures}
%\begin{table}
%\begin{tabular}{lll}
%\textbf{Type Name} & \textbf{Example} & \textbf{Description} \\
%\hline
%list & [1, 2, 3] & Ordered collection \\
%tuple & (1, 2, 3) & Immutable ordered collection \\
%dict & \{'a':1, 'b':2, 'c':3\} & Unordered (key,value) mapping \\
%set & \{1, 2, 3\} & Unordered collection of unique values \\
%\end{tabular}
%\end{table}
%Page 30-31 of A Whirlwind Tour of Python by VanderPlas.
% \begin{alertblock}{Mutable}
% Can be changed and modified
% \end{alertblock}
% \begin{alertblock}{Immutable}
% Can not be changed or modified
% \end{alertblock}
%\end{frame}
%
%\begin{frame}[fragile]{Lists are amazing}
%Lists
%\begin{itemize}
%\item basic \textbf{ordered} and \textbf{mutable} data collections
%\item Lists can be any shape and contain any data type
%\item you can have lists, floats, integers, tuple, dictionaries, sets in lists
%\item a float of 10.0 can be added to a list x by x.append(10.0)
%\item list x can be sorted by x.sort()
%\item the number of items in list x can be found with len(x)
%\end{itemize}
%\end{frame}
%
%\begin{frame}{Pimp my list}
%\begin{figure}
% \includegraphics[width=1.0\textwidth]{figs/pimpmylist.jpg}
%\end{figure}
%\end{frame}
%
%\begin{frame}{Listception}
%\begin{figure}
% \includegraphics[width=1.0\textwidth]{figs/listception.jpg}
%\end{figure}
%\end{frame}
%
%\begin{frame}[fragile]{An example list}
%\begin{minted}
%{python}
%x = [] # initialize an empty list
%x.append(0.0) # append float 0.0 to x
%x.append(1) # append integer 1 to x
%x.append([3,4,'hi',(10,8)]) # append a list with a tuple to x
%x.sort() # sort x from low to high
%n = len(x) # count the number of items in list x
%print('There are ',n,' items in list x')
%print(x)
%\end{minted}
%\textbf{Note}: x.sort() doesn't work in this case with Python 3 since you would need to compare different data types!!!
%\end{frame}
%
%\begin{frame}[fragile]{List forward indexing - lists start at 0}
%\begin{minted}
%{python}
%x = [7, 77, 777, 7777]
%\end{minted}
%The first item in the list can be called using
%\begin{minted}
%{python}
%in : x[0]
%out: 7
%\end{minted}
%The second item of the list can be called using
%\begin{minted}
%{python}
%in : x[1]
%out: 77
%\end{minted}
%The third item of the list can be called using
%\begin{minted}
%{python}
%in : x[2]
%out: 777
%\end{minted}
%The last item of the list can be called using
%\begin{minted}
%{python}
%in : x[3]
%out: 7777
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{List backward indexing - last index item in Python is -1}
%\begin{minted}
%{python}
%x = [7, 77, 777, 7777]
%\end{minted}
%The last item in the list can be called using
%\begin{minted}
%{python}
%in : x[-1]
%out: 7777
%\end{minted}
%The second to last item of the list can be called using
%\begin{minted}
%{python}
%in : x[-2]
%out: 777
%\end{minted}
%The third to last item of the list can be called using
%\begin{minted}
%{python}
%in : x[-3]
%out: 77
%\end{minted}
%The fourth to last item of the list can be called using
%\begin{minted}
%{python}
%in : x[-4]
%out: 7
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{List slicing}
%\begin{minted}
%{python}
%x = [7, 77, 777, 7777]
%\end{minted}
%List slicing is [startPoint : endPoint] where startPoint is inclusive and endPoint is exclusive. In Mathematics would define define the interval as [startPoint, endPoint).
%
%If we wanted the first and second item in a list
%\begin{minted}
%{python}
%in : x[0:2]
%out: [7, 77]
%\end{minted}
%
%So if we want the second through fourth item in list x
%\begin{minted}
%{python}
%in : x[1:4]
%out: [77, 777, 7777]
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{Slicing with step size}
%\begin{minted}
%{python}
%x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
% 10, 11, 12, 13, 14, 15,
% 16, 17, 18, 19] # creates a list of integers
%\end{minted}
%
%We can slice with [startPoint:endPoint:stepSize], just like before, but now stepSize is the step size of our slice.
%
%\begin{minted}
%{python}
%in : x[0:20:2]
%out: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
%\end{minted}
%
%\begin{minted}
%{python}
%in : x[0:20:5]
%out: [0, 5, 10, 15]
%\end{minted}
%
%\begin{minted}
%{python}
%in : x[1:20:3]
%out: [1, 4, 7, 10, 13, 16, 19]
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{Reverse the order of a list}
%Sometimes it is useful to reverse the order of a list. We can do this by consider a backwards slice.
%\begin{minted}
%{python}
%x = [7, 77, 777, 7777]
%\end{minted}
%
%So to see the reverse order of x we would run
%\begin{minted}
%{python}
%in : x[::-1]
%out: [7777, 777, 77, 7]
%\end{minted}
%\end{frame}
%
%
%
%\begin{frame}[fragile]{Tuples}
%Tuples are just like lists, except you define a tuple with parentheses instead of square brackets. List indexing a slicing of Tuples works exactly like lists, and you'll use square brackets to call items of a tuple.
%
%\textbf{Tuples are immutable} which means that once they are created they can't be modified in any way. I hardly ever use Tuples.
%
%Let's create a tuple of 2, 4, 6.
%\begin{minted}
%{python}
%x = (2, 4, 6)
%\end{minted}
%
%\begin{minted}
%{python}
%in : x[0]
%out: 2
%\end{minted}
%
%
%\begin{minted}
%{python}
%in : x[-1]
%out: 6
%\end{minted}
%
%
%\end{frame}
%
%\begin{frame}[fragile]{Dictionaries}
%Dictionaries map keys to values. There is no index with dictionaries, instead there is a key. Dictionaries are sometimes used to pass parameters into a function.
%
%Let's take a look at this param dictionary for the XGDBoost library as an example dictionary. \url{http://xgboost.readthedocs.io/en/latest/python/python_intro.html}
%
%\begin{minted}
%{python}
%param = {'max_depth':2, 'eta':1, 'silent':1,
% 'objective':'binary:logistic' }
%param['nthread'] = 4
%param['eval_metric'] = 'auc'
%\end{minted}
%
%We don't can add keys to the dictionary at any time! Let's take a look at param.
%\begin{minted}
%{python}
%in : print(param)
%out: {'silent': 1, 'eval_metric': 'auc', 'nthread': 4,
% 'eta': 1, 'objective': 'binary:logistic', 'max_depth': 2}
%\end{minted}
%
%\end{frame}
%
%\begin{frame}[fragile]{Dictionaries - param continued}
%Find values of keys with square brackets.
%\begin{minted}
%{python}
%in : param['objective']
%out: 'binary:logistic'
%\end{minted}
%
%We can easily assign a new value for a key
%\begin{minted}
%{python}
%in : param['objective'] = 'reg:linear'
%in : print(param['objective'])
%out: 'reg:linear'
%\end{minted}
%\end{frame}
%
%\begin{frame}[fragile]{Sets}
%Sets are like lists and tuples, but are defined with curly brackets. Sets obey mathmatical set definitions. VanderPlas provides a good example on page 36-37. Which I'll show here.
%\begin{minted}
%{python}
%in : primes = {2, 3, 5, 7}; odds = {1, 3, 5, 7, 9}
%in : primes.union(odds) # union of primes and odds
%out: {1, 2, 3, 5, 7, 9}
%in : primes.intersect(odds) # intersection of primes and odds
%out: {3, 5, 7}
%in : primes.difference(odds) # items in primes but not odds
%out: {2}
%in : primes.symmetric_difference(odds) # items in just one set