Commit c8571e4b by Thibaut.Lunet

### TL: finished slides (still scripts to be added, and final corrections)

parent 62ec1cae
 ... ... @@ -34,8 +34,15 @@ nl = [['vive', 'la'], ['saucisse', 2], 'Toulouse'] # Access sublist element : nl[0] = ['vive', 'la'] # Access final element : nl[0][1] = 'la', nl[1][0] = 'saucisse' # List definition l1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # -- equivalent (shorter) formulation l1 = [i for i in range(10)] # List operation l11 = [i + 1 for i in l1] # List comprehension l1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] l2 = [3 * n + 1 for n in l1 if n % 2 == 0] # l2 = [7, 13, 19, 25, 31] # %% Slide: Dictionaries ... ... @@ -75,21 +82,33 @@ while i < 10: # %% Slide: Function definition def add(a, b = 1): def add(a, b=1): # NO NEED to define the type, b has a default value return a + b # add(0.5, 2) = 2.5 # add(1) = 2 # add() -> ERROR # No types # Parameters by default # Possibility of having a variable number of parameters # Possibility of having a variable number of parameters and outputs def doSomething(x, y, z, p1=1, p3='red'): return p1*(x+y), p3+str(z) # returns a list of two elements out = doSomething(1, 2, 3) # out[0] = 3, out[1] = 'red3' # -- shorter equivalent way value, flag = doSomething(1, 2, 3) # value = 3, flag = 'red3' # General form of a function (cf. function plot of matplotlib) def myFuncThatDoThings(*args, **kwargs): pass # args is a list, with non keyword argument (ex: a in add) # kwargs is a dictionnary, with keywords arguments (ex: b=1 in add) # * and ** are just a notation to 'unpack' list and dictionnary # keywords arguments ALWAYS at the end (ex: add(b=1, a) -> ERROR) # %% Slide: File IO infile = open("infile.dat", "r") # Opens the file for reading ... ... @@ -113,7 +132,7 @@ outfile.write(s + '\n') outfile.close() # Close file to release memory # %% Slide: Numpy ... ... @@ -148,6 +167,8 @@ M = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]]) M[1:2, 0:2] # Matrix [5, 6] M[0:2] # First two rows M[:, 1:3] # Second and third columns M[-1, :] # Last line # INDEX STARTS AT 0 !!! # We already have some built-in matrices: ... ... @@ -201,19 +222,19 @@ plt.show() # %% Slide: Sympy from sympy import * import sympy as sy # Import package x = symbols('x') y = symbols('y') x = sy.symbols('x') y = sy.symbols('y') # Create symbolic variables a = x + y # x + y b = a - x # y c = expand(a**2) # x**2 + 2*x*y + y**2 d = factor(c) # (x + y)**2 c = sy.expand(a**2) # x**2 + 2*x*y + y**2 d = sy.factor(c) # (x + y)**2 init_printing(use_unicode = True) sy.init_printing(use_unicode = True) # Generates a nice human-readable output F = exp(x)*sin(x) ... ... @@ -239,7 +260,7 @@ dsolve(Eq(lhs, rhs), u(t)) # u(t) = C2*exp(-t) + (C1 + t/2)*exp(t) latex(Integral(cos(x)**2, (x, 0, pi))) # LaTeX code! # %% Old Slide : Function definition def funcA(a, b = 1): return a + b ... ...
 ... ... @@ -6,9 +6,9 @@ Contains *.tex*, *.pdf*, etc ... files for the presentation of the PhD seminar. - [ ] 20 min presentation (slides breakdown) - [x] How to get Python (TL) - [ ] History (TL) - [x] What are we talking about (TL) - [x] Functioning principles (TL) - [x] Python vs. Others (TL: Aitor, je te corriger des choses si tu le sens) - [ ] Functioning principles (TL) - [x] Practical tools (TL) - [ ] 30 min hands-on examples ... ... @@ -17,14 +17,16 @@ Contains *.tex*, *.pdf*, etc ... files for the presentation of the PhD seminar. - [x] Lists (AP) - [x] Dictionaries (AP) - [x] Conditional structures (AP) - [ ] Function definition (AP) - [x] Function definition (AP) - [x] File I/O : reading and writing a file (from simple text, and examples of more complex tools ...) (AP) - [ ] Numpy + Scipy introduction (TL) - [x] Using Numpy to manipulate arrays (AP) - [x] Overview of Scipy functionalities (AP) - [x] Numpy + Scipy introduction (TL) - [x] Numpy Basics I (AP) - [x] Numpy Basics II (AP) - [x] To go further with Numpy and Scipy (TL) - [x] Data visualization with Matplotlib (AP) - [ ] Sympy introduction (TL) - [ ] Symbolic computation with Sympy (AP) - [x] Sympy, more than just another py-word game (TL) - [x] To go further withSympy (TL) - [x] Conclusion (TL) [MarkDown documentation](https://docs.gitlab.com/ee/user/markdown.html) - General synthax for *.md* files

46.2 KB | W: | H:

54.5 KB | W: | H:

• 2-up
• Swipe
• Onion skin

153 KB | W: | H:

40.5 KB | W: | H:

• 2-up
• Swipe
• Onion skin

806 KB

No preview for this file type
 ... ... @@ -63,17 +63,63 @@ \end{enumerate} \end{frame} \begin{frame}{History} XXX \begin{frame}{What are we talking about} \begin{block}{A little history} \begin{itemize} \item Programming language conceived by a Monty Python fan in the 80's \item First released in 1991, then \begin{itemize} \item Python 2 in 2000 (community backed development, support $\rightarrow$ 2020) \item Python 3 in 2008 (major revision) \end{itemize} \end{itemize} Current versions (2.7, 3.6) are not entirely compatible, but very close \end{block} \begin{block}{Main motivations} Developers wanted to create a language that would be \vspace{-10pt} \begin{itemize} \item general purpose (they really got that !) \item highly extensible and modular (dynamic language) \item beautiful, simple, \textbf{easily readable} \end{itemize} \end{block} \vspace*{-20pt} \end{frame} \begin{frame}{Functioning principles} \begin{block}{Pre-compilation of code files} \centering \includegraphics[width=0.8\linewidth]{cpython} \vspace*{-20pt} \begin{itemize} \item Allows partial code optimization \item Totally transparent to user \item Portability on every architecture \end{itemize} \end{block} Python core (Virtual Machine) is written in C: \vspace*{-5pt} \begin{itemize} \item Easy interface with other compiled languages (C/C++, Fortran) \item Same speed for read/write files as C \end{itemize} \vspace*{-20pt} \end{frame} \begin{frame}{Python vs. Others (Matlab, Fortran, C/C++, ...)} \begin{itemize} \item License-free and open-source ($\neq$ Matlab) \item Huge users community, many (free) packages for many applications \item Extremely easy of use for non-I-love-programming people \\ ($\neq$ Fortran, C/C++) \item Easy interface with other (more-efficient) programming languages \\ $\Rightarrow$ computation can be accelerated using Fortran or C/C++ \item Computation can be accelerated using Fortran or C/C++ library ... \item Can scale to very large problems (parallel computing, ...) \item Structured and friendly ways for developing library ($\neq$ Matlab) ... ... @@ -93,11 +139,6 @@ Python = many advantages, with very few drawbacks ! \end{center} \end{frame} \begin{frame}{Functioning principles} XXX \end{frame} \begin{frame}{Practical tools} \vspace{5pt} ... ... @@ -176,7 +217,7 @@ \begin{frame}{Basic variables types and operations} % \pythonCode Slide codes at: \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/code-examples}{python-math/examples/code\-examples.py} \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/code-examples}{python-math/examples/code-examples.py} \vspace*{5pt} \includegraphics[width=0.9\linewidth]{code-basic-variables} ... ... @@ -267,26 +308,65 @@ \end{frame} \begin{frame}{Numpy and Scipy introduction} XXX \begin{frame}{Numpy and Scipy, what for ?} \begin{center} Loops in python are (REALLY) slow\\ $\Rightarrow$ do algebraic computation in C (or Fortran) \end{center} \begin{block}{Numpy : interface for array manipulation} \begin{itemize} \item Data are stored in contiguous memory location \item Operations on arrays are done in C \item Rely on BLAS implementation for algebraic computation \end{itemize} \end{block} \begin{block}{Scipy : companion package for scientific computing} \begin{itemize} \item Many functions for linear algebra, optimization, interpolation, fft... \item Interface with C and Fortran optimized routine\\ (LAPACK, FFTW, QUADPACK, ... and many others !) \end{itemize} \end{block} \end{frame} \begin{frame}{Numpy I} \begin{frame}{Numpy basics I} \includegraphics[width=0.9\linewidth]{code-numpy1} \end{frame} \begin{frame}{Numpy II} \begin{frame}{Numpy basics II} \includegraphics[width=0.8\linewidth]{code-numpy2} \end{frame} \begin{frame}{Scipy} \includegraphics[width=0.9\linewidth]{code-scipy} \begin{frame}{To go further with Numpy and Scipy} % \includegraphics[width=0.9\linewidth]{code-scipy} \small \vspace{5pt} \begin{block}{Numpy examples :} \begin{itemize} \item Call Fortran routines to accelerate computations \item Easily read and write files with single line coding \end{itemize} \end{block} \vspace*{-7pt} ... and more in \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/numpy}{python-math/examples/numpy} directory \vspace*{6pt} \begin{block}{Scipy examples :} \begin{itemize} \item Data regression using least square minimization \item Eigenvalue computation of the tri-dimensional advection operator \end{itemize} \end{block} \vspace*{-7pt} ... and more in \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/scipy}{python-math/examples/scipy} directory \\ See also \href{https://docs.scipy.org/doc/scipy/reference/tutorial/}{Scipy tutorials} on the Internet \end{frame} \begin{frame}{Matplotlib I} \begin{frame}{Data visualization with Matplotlib I} \includegraphics[width=0.8\linewidth]{code-matplotlib1} \centering \includegraphics[width=0.4\linewidth]{plot1} ... ... @@ -296,15 +376,57 @@ \includegraphics[width=0.9\linewidth]{code-matplotlib2} \centering \includegraphics[width=0.4\linewidth]{plot2} ... and more in \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/matplotlib}{python-math/examples/matplotlib} directory \end{frame} \begin{frame}{Sympy introduction} XXX \begin{frame}{Sympy, more than just another py-word game} If you are interested in \begin{itemize} \item Sparing few neurons by not doing computation by hand \item Verifying some solutions you will give to students \item Obtaining a direct latex translation of some ugly formula \end{itemize} \begin{center} Sympy can help you ! \end{center} \begin{itemize} \item Symbolic optimized computation core in python \item Can combine numerical calculation with Numpy \item Allow some nice output form within Spyder \end{itemize} \end{frame} \begin{frame}{Sympy} XXX \begin{frame}{To go further with Sympy} \begin{block}{Scipy examples :} \begin{itemize} \item Block matrix computation with non-commutative elements \item Compute interpolation formula for non-structured grid \item Latex translation of symbolic formula \end{itemize} \end{block} \vspace*{-7pt} ... and more in \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples/sympy}{python-math/examples/sympy} directory \\ See also \href{http://docs.sympy.org/latest/tutorial/index.html}{Sympy Tutorials} on the Internet \end{frame} \begin{frame}{Conclusion} Here was just presented a tiny part of python application for researchers\\ $\Rightarrow$ many other nice things are also possible \begin{itemize} \item Writing code documentation, and include math formula \item Create and organize packages for particular applications \item Benefit from the object-oriented programming to facilitate modularity and code development \end{itemize} Do not hesitate to look at \href{https://gitlab.unige.ch/Thibaut.Lunet/python-math/tree/master/examples}{python-math/examples} for other advanced examples ... \begin{center} \bfseries Thanks for watching ! \\ ... we hope you enjoy at least some parts ... \end{center} \end{frame} \end{document} \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!