csc321 - python tutorialrgrosse/csc321/tutorial1.pdf · kaustav kundu csc321 - python tutorial...
TRANSCRIPT
![Page 1: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/1.jpg)
CSC321 - Python Tutorial
Kaustav Kundu
January 15, 2015
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 1 / 14
![Page 2: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/2.jpg)
Why Python?
1 High level scripting language.
2 Rich library of modules, including third party modules/add-ons.
3 FOSS (Free and Open Source Software) - unlike Matlab.
4 Extremely good documentation (https://www.python.org/doc/) andsupport (stackoverflow, etc.).
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 2 / 14
![Page 3: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/3.jpg)
Python Development Environment
1 Command Line InterpreterType python from the command line to use the python interpreter
2 Editor(a) vim, emacs(b) IDE: Spyder
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 3 / 14
![Page 4: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/4.jpg)
Python Development Environment
1 Command Line InterpreterType python from the command line to use the python interpreter
2 Editor(a) vim, emacs(b) IDE: Spyder
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 3 / 14
![Page 5: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/5.jpg)
Operations
1 Arithmetic+,−, ∗, /,%(modulus), ∗ ∗ (exponent), //(floor division)
2 Relational>,<,>=, <=,==, ! =
3 Logicalor, and, not
4 Bitwise&, |, ∧, ∼ , <<,>>
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 4 / 14
![Page 6: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/6.jpg)
Lists
1 Initialization
2 Methods: append, extend, insert, remove, count, index,
sort, reverse
3 List comprehensions
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 5 / 14
![Page 7: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/7.jpg)
Lists
1 Initialization
2 Methods: append, extend, insert, remove, count, index,
sort, reverse
3 List comprehensions
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 5 / 14
![Page 8: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/8.jpg)
Lists
1 Initialization
2 Methods: append, extend, insert, remove, count, index,
sort, reverse
3 List comprehensions
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 5 / 14
![Page 9: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/9.jpg)
Lists
1 “Sum” of lists
2 2D lists
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 6 / 14
![Page 10: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/10.jpg)
Lists
1 “Sum” of lists
2 2D lists
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 6 / 14
![Page 11: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/11.jpg)
Lists
1 “Sum” of lists
2 2D lists
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 6 / 14
![Page 12: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/12.jpg)
Arrays
Initialization
Element-wise operations
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 7 / 14
![Page 13: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/13.jpg)
Arrays
Initialization
Element-wise operations
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 7 / 14
![Page 14: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/14.jpg)
Arrays
Dot Products
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 8 / 14
![Page 15: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/15.jpg)
Arrays
Matrix Multiplication
Transpose
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 9 / 14
![Page 16: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/16.jpg)
Arrays
Matrix Multiplication
Transpose
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 9 / 14
![Page 17: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/17.jpg)
Arrays vs Lists
1 Difference between lists and arrays is similar to that between matricesand cell arrays in MATLAB.
2 All elements in arrays have to be of the same data type, specified atthe time of creation.
3 Usually memory efficient, may not be time efficient compared to lists.
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14
![Page 18: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/18.jpg)
Arrays vs Lists
1 numpy.array provides a lot of advantages to perform matrixoperations, like transpose, inverse, eigen values, etc.
2 For more details look at numpy and scipy documentations.
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 11 / 14
![Page 19: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/19.jpg)
Dictionary
Equivalent to std::map in C++.
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 12 / 14
![Page 20: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/20.jpg)
Modules
# Fibonacci numbers module
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b,
a, b = b, a+b
def fib2(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 13 / 14
![Page 21: CSC321 - Python Tutorialrgrosse/csc321/tutorial1.pdf · Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 10 / 14. Arrays vs Lists 1 numpy.array provides a lot of advantages](https://reader034.vdocument.in/reader034/viewer/2022052423/5f07762e7e708231d41d1967/html5/thumbnails/21.jpg)
Classes
Kaustav Kundu CSC321 - Python Tutorial January 15, 2015 14 / 14