35
An Introduction to Python for Scientists Hands-On Tutorials Ahmed Attia Statistical and Applied Mathematical Science Institute (SAMSI) 19 TW Alexander Dr, Durham, NC 27703 attia@ {samsi.info || vt.edu} Department of Mathematics, North Carolina State University, [email protected] SAMSI Undergraduate Workshop on Optimization; February 27, 2017 Hands-On Tutorials [1/35] February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

An Introduction to Python for ScientistsHands-On Tutorials

Ahmed Attia

Statistical and Applied Mathematical Science Institute (SAMSI)19 TW Alexander Dr, Durham, NC 27703

attia@ {samsi.info || vt.edu}

Department of Mathematics, North Carolina State University,[email protected]

SAMSIUndergraduate Workshop on Optimization; February 27, 2017

Hands-On Tutorials [1/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 2: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Ahmed Attia [[email protected], [email protected]]NCSU, Math Department & SAMSI

Sercan Yildiz [[email protected] ] Peter Diao[[email protected]]UNC Chapel Hill & SAMSI Duke & SAMSI

Missy Gaddy [[email protected] ] Jeff LaComb [ [email protected] ]NC State University Duke University, Math Department

Hands-On Tutorials [2/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 3: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Outline

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials [3/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 4: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Getting Started with Python [4/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 5: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

I According to (Python.org ),

“Python is an interpreted, object-oriented, high-level programming languagewith dynamic semantics.

Its high-level built in data structures, combined with dynamic typing anddynamic binding, make it very attractive for Rapid Application Development,

as well as for use as a scripting or glue language to connect existingcomponents together.”

I Why Python:

1. https://www.continuum.io/why-python

2. https://www.python.org/doc/essays/comparisons/

3. http://www.bestprogramminglanguagefor.me/why-learn-python

4. https://www.codefellows.org/blog/

5-reasons-why-python-is-powerful-enough-for-google/

Hands-On Tutorials Getting Started with Python [5/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 6: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Learn Python: where should I start?I Textbooks (for Scientists):

1. Python for Scientists2. A Primer on Scientific Programming with Python3. Python Scripting for Computational Science

I Phone/Tablet Apps: Learn Python- Android: https://play.google.com/store/apps/details?id=com.sololearn.python&hl=en

- IPhone/IPad: https://itunes.apple.com/us/app/learn-python-pro/id953972812?mt=8

I Python online Documentation: https://docs.python.org/2/

I Practice, Practice,Practice,

Hands-On Tutorials Getting Started with Python [6/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 7: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Basic Concepts

I Python script files have extension (.py), and compiled code files(executables) have extension (.pyc).

I Python scripts can be written using any plain text editor.

I Avoid using SOLID Tabs.Make sure Tabs are converted to SPACES (check your editor settings).

I INDENTATION is Extremely important. (For now, make sure all script linestart at the beginning of the line.)

I Python is CASE-SENSITIVE.

Hands-On Tutorials Getting Started with Python [7/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 8: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Running Python codeI IPython : is an interactive command shell originally developed for Python,

that supports tab completion, and history amongst other features. Thismakes working with Python very similar to working with MATLAB .

I To run a Python script:1. from a terminal using the command: $ python [script-name.py]

2. from IPython: $ run [script-name.py]

I Jupyter Notebook : (Formerly known as IPython Notebook) is aninteractive rich computational environment, built around IPython, best suitedfor learning, teaching, and designing tutorials.

I Task:

1. → http://people.cs.vt.edu/~attia/Tutorials/samsi_02_27/2. write a “Hello World” program in:

I a python script and run it,

II in IPython shell,

III in a Jupyter notebook.

Hands-On Tutorials Getting Started with Python [8/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 9: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Terminal output; print

I Now, given the last task, you know that to print anything to the screen, wewill need to use the “print” function (or statement)

I Python’s ‘‘print’’ function can be used to print a “string representation”of an ‘‘object’’ , e.g. string, number, etc.:

print(<object>) or print <object>

I The most obvious object to be printed to a screen is a String; one of themain datatypes in Python is str . (Next)

I IF you like to complicate things, check:

print(str([object])), vs. print([object]. str ())

I Task: open the script lesson0 terminal output.py

Hands-On Tutorials Getting Started with Python [9/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 10: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Data types, and variable assignment I

I Python supports a variety of data types, including:

1. Strings: str

2. Numerical types: int, long, float, complex

3. Boolean: bool

I To check/view the data type of an object, you can use:type([object name])

I Python, by default, allocates memory dynamically, and does not requiredata type declaration; unlike Fortran, C, etc.

I Variables are created with dynamic binding; assignment is done usingassignment operator ‘‘=’’.

variable-name = variable value

I Multiple assignment (with dynamic binding) is allowed , e.g. x = y = 3.

Hands-On Tutorials Getting Started with Python [10/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 11: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Data types, and variable assignment III Variable naming rules:

1. Variables names must start with a letter or an underscore,2. the remainder of the name may consist of letters, numbers, or underscores,3. variable name is case sensitive.4. variable name (identifier) length can be one character or more, and should be

meaningful.

I Examples:

Correct Incorrectx , i , 1x , ,

x , radius, radius, radius, radi us, radi − uspar 1, peremeter0 2 , etc. x$, s #, etc.

I Variable names starting with underscore will play vital role when we learnhow to import data from Python modules.

I Task: open the script lesson1 datatypes.py

Hands-On Tutorials Getting Started with Python [11/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 12: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Basic numerical, string, and boolean operations [12/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 13: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Numerical arithmetics

I Python can apply one or more numerical arithmetic operations, to integers,real numbers, or both.

1. Addition, subtraction: [+, −]

2. Multiplication, division, quotient, remainder(modulo): [∗, /, //, %]

3. Unitary: [+, −]

4. Exponentiation: [**]

Priority (precedence) is from “lowest” to “highest”. Override, and arrangeoperations using round braces ( ).

I Question: What is the result of the following operation:

−3 ∗ ∗2 + 24//12%4/3− 5 ∗ (2/3) ∗ (1/4.)

Try by hand, then use IPython, and check your answer!

Hands-On Tutorials Basic numerical, string, and boolean operations [13/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 14: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

String operations

I You should know by now, that strings are defined, using single, double, ortriple-double quotes (“docstring”).

I Strings are saved into variables of “str” data type. Try the following:x = ’this is a string’

print(type(x))

I Simple string operations:I You can use addition ’+’ to add two strings,I you can replicate a string using ’*’ (multiply a string by an INTEGER)

I A string can be formatted easily using escape characters, e.g. \n, \r, \t.You can also use %[datatype] to insert something in a string,

I Task:What is the result of the following expression?

" Lesson%d \n is \t pointless%s " % (0, ’: ’*2)

Hands-On Tutorials Basic numerical, string, and boolean operations [14/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 15: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Boolean (logical) operations

I Logical operations include:

>, < , ==, >=, <=, !=

in, not in, is, is not

not, and, or

I You can also use double expressions such as: a < x < b.

I The priority of all these is less than arithmetics, and is ranked from highest tolowest as follows:

1. >, < , ==, >=, <=, !=, in, not in, is, is not

2. not

3. and

4. or

I For full operator precedence, check:https://docs.python.org/2/reference/expressions.html

Hands-On Tutorials Basic numerical, string, and boolean operations [15/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 16: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Basic numerical, string, and boolean operations

Task:

1. Open the script lesson2 numbers arithmetics.py

2. Open the script lesson2 string operations.py

3. Open the script lesson2 boolean expressions.py

Hands-On Tutorials Basic numerical, string, and boolean operations [16/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 17: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Iterables, and basic data structures [17/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 18: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Iterables, and basic data structures

I An “iterable” is a Pythonic term, refers to any object capable of returning itsmembers one at a time.

I Basic examples include:

1. lists,

2. tuples,

3. dictionaries,

4. sets,

5. strings.

I Task:To learn how to create, access, or modify these objects:

1. Open the script lesson3 lists.py2. Open the script lesson3 tuples.py3. Open the script lesson3 dictionaries.py

Hands-On Tutorials Iterables, and basic data structures [18/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 19: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Branching, and Looping [19/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 20: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Branching, and Looping: if, for, while

I We will learn this lesson directly from the code examples.

I Task:

1. Open the script lesson4 if statement.py2. Open the script lesson4 loops.py

Hands-On Tutorials Branching, and Looping [20/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 21: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Functions [21/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 22: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Functions

I We will learn this lesson directly from the code examples.

I Task:Open the script lesson5 functions.py

Hands-On Tutorials Functions [22/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 23: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Python Modules and Packages [23/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 24: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Using Python ModulesI The components of a Python module, or a (.py) file can be imported into

the current working space, using the ’import’ statement. Examples(discussed further in class)

1. import [module name]

2. import module1, module2

3. import module1 as alias

4. from [module name] import [variable, function, class, submodule] <as alias>

I Once a module is imported, its contents can be accessed using the [.]operator

I The following statement imports everything(ish) from a module:

from [module name] import *

I Popular packages for scientific computing: math, numpy, scipy, matplotlib,statsmodel, re, etc.

I Check this: https://pythontips.com/2013/07/30/

20-python-libraries-you-cant-live-without/

I Task: Open the script lesson6 modules.py

Hands-On Tutorials Python Modules and Packages [24/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 25: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Scientific Packages: Numpy & Scipy [25/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 26: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Numpy

I According to (http://www.numpy.org/):NumPy is the fundamental package for scientific computing with Python.

I Numpy contains, among other things:

1. a powerful N-dimensional array object

2. sophisticated “broadcasting” functions

3. tools for integrating C/C++ and Fortran code

4. useful linear algebra, Fourier transform, and random number capabilities

I Task: Open the script lesson7 numpy intro.py

Hands-On Tutorials Scientific Packages: Numpy & Scipy [26/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 27: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Scipy: sparsity and more!

I Once you become familiar with Numpy, you will realize that some linearalgebra and statistical tools are not provided.

I Amongst others, Numpy does not provide sparse linear algebra functionalities.This is the time to start learning/using Scipy

I According to (https://docs.scipy.org/doc/scipy/reference/),SciPy (pronounced Sigh Pie) open-source software for mathematics, science,and engineering.

I Task: Open the script lesson8 scipy intro.py

Hands-On Tutorials Scientific Packages: Numpy & Scipy [27/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 28: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials File I/O [28/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 29: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Files, input, and output operationsI You can open a file, to read ’r’, write ’w’, modify ’r+’, or append ’a’ .

file id = open([file name or path], mode=’r’)

<Do stuff with the file>

file id.method()

<Do stuff with the file>

file id.close()

I A better approach:with open([file name or path]) as file id:

Do stuff with the file>

file id.method()

<Do stuff with the file>

I Matlab (.mat) files:import scipy.io as file io

file contents = file io.loadmat([matlab mat file name or

path])

I Task: Open the script lesson9 fileIO.py

Hands-On Tutorials File I/O [29/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 30: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Plotting: matplotlib [30/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 31: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Plotting: matplotlib

I According to (http://matplotlib.org/):

Matplotlib is a Python 2D plotting library which produces publication qualityfigures in a variety of hardcopy formats and interactive environments across

platforms. Matplotlib can be used in Python scripts, the Python andIPython shell, the jupyter notebook, web application servers, and four

graphical user interface toolkits.

I Task: Open the script lesson10 matplotlib.py

Hands-On Tutorials Plotting: matplotlib [31/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 32: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials OOP: Python Classes [32/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 33: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

OOP: Python Classes

I Task:Open the script lesson11 classes intro.py

Hands-On Tutorials OOP: Python Classes [33/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 34: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Getting Started with Python

Basic numerical, string, and boolean operations

Iterables, and basic data structures

Branching, and Looping

Functions

Python Modules and Packages

Scientific Packages: Numpy & Scipy

File I/O

Plotting: matplotlib

OOP: Python Classes

Additional topics

Hands-On Tutorials Additional topics [34/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)

Page 35: An Introduction to Python for Scientists - Hands-On Tutorialspeople.cs.vt.edu/~attia/Files/Classes/PythonIntro/... · An Introduction to Python for Scientists Hands-On Tutorials Ahmed

Additional topicsI Optimization:

1. scipy.optimize: (https://docs.scipy.org/doc/scipy-0.18.1/reference/tutorial/optimize.html)

2. PyOpt: (http://www.pyopt.org/)3. CVXOPT: (http://cvxopt.org/)

I Neural Networks, and Deep Learning:1. Neural Networks in Scikit-learn: (http://scikit-learn.org/stable/

modules/neural_networks_supervised.html)2. Deep Learning:

2.1 http://deeplearning.net/tutorial/

2.2 https:

//elitedatascience.com/keras-tutorial-deep-learning-in-python

2.3 http://caffe.berkeleyvision.org/

I Wrappers:1. SWIG: (http://www.swig.org/)2. F2PY: (https://docs.scipy.org/doc/numpy-dev/f2py/)

I Statistical Analysis:(http://www.scipy-lectures.org/packages/statistics/index.html)

I Inverse Problems and Data Assimilation: (Next Tutorial)

Hands-On Tutorials Additional topics [35/35]

February 27, 2017: An Introduction to Scientific Python, Ahmed Attia. (http://samsi.info)