|
1 #+LaTeX_CLASS: beamer |
|
2 #+LaTeX_CLASS_OPTIONS: [presentation] |
|
3 #+BEAMER_FRAME_LEVEL: 1 |
|
4 |
|
5 #+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} |
|
6 #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) |
|
7 #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC |
|
8 |
|
9 #+LaTeX_CLASS: beamer |
|
10 #+LaTeX_CLASS_OPTIONS: [presentation] |
|
11 |
|
12 #+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} |
|
13 #+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
|
14 |
|
15 #+LaTeX_HEADER: \usepackage{listings} |
|
16 |
|
17 #+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, |
|
18 #+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
|
19 #+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
|
20 |
|
21 #+TITLE: Using python modules |
|
22 #+AUTHOR: FOSSEE |
|
23 #+EMAIL: |
|
24 #+DATE: |
|
25 |
|
26 #+DESCRIPTION: |
|
27 #+KEYWORDS: |
|
28 #+LANGUAGE: en |
|
29 #+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t |
|
30 #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc |
|
31 |
|
32 * Outline |
|
33 - Running python scripts from command line |
|
34 - Importing python modules |
|
35 - Importing scipy \& pylab modules |
|
36 - About python standard library. |
|
37 * Running Python script from command line |
|
38 - Create a script, open text editor and type the following |
|
39 : print "hello world!" |
|
40 : print |
|
41 - Save the script as ~hello.py~ |
|
42 * Running Python script from command line (cont'd) |
|
43 - Run the script |
|
44 : $ python hello.py |
|
45 /Syntax :/ *python filename* |
|
46 * Four plot problem |
|
47 #+begin_latex |
|
48 \begin{center} |
|
49 \includegraphics[scale=0.4]{four_plot} |
|
50 \end{center} |
|
51 #+end_latex |
|
52 * Fix ~linspace()~ problem |
|
53 : from scipy import * |
|
54 * Fix ~plot()~ problem |
|
55 : from pylab import * |
|
56 * Better way of fixing |
|
57 : from scipy import linspace |
|
58 instead of |
|
59 : from scipy import * |
|
60 ~*~ means import all functions from name-space ~scipy~. |
|
61 * Instead of ~*~ |
|
62 : from scipy import linspace, pi, sin |
|
63 : from pylab import plot, legend, annotate |
|
64 : from pylab import xlim, ylim, title, show |
|
65 Is better than, ~from scipy import *~ \& ~from pylab import *~. |
|
66 * Another Fix |
|
67 #+begin_src python |
|
68 import scipy |
|
69 import pylab |
|
70 x = scipy.linspace(-5*scipy.pi, 5*scipy.pi, 500) |
|
71 pylab.plot(x, x, 'b') |
|
72 pylab.plot(x, -x, 'b') |
|
73 pylab.plot(x, scipy.sin(x), 'g', linewidth=2) |
|
74 pylab.plot(x, x*scipy.sin(x), 'r', linewidth=3) |
|
75 pylab.legend(['x', '-x', 'sin(x)', 'xsin(x)']) |
|
76 pylab.annotate('origin', xy = (0, 0)) |
|
77 pylab.xlim(-5*scipy.pi, 5*scipy.pi) |
|
78 pylab.ylim(-5*scipy.pi, 5*scipy.pi) |
|
79 #+end_src |
|
80 * Exercise 1 |
|
81 Write a python script to plot a sine wave from |
|
82 #+begin_latex |
|
83 $-2\Pi$ |
|
84 #+end_latex |
|
85 to |
|
86 #+begin_latex |
|
87 $2\Pi$ |
|
88 #+end_latex |
|
89 . |
|
90 * What is a module? |
|
91 Module is simply a file containing Python definitions and |
|
92 statements. Definitions from a module can be imported into other |
|
93 modules or into the main module. |
|
94 * Python standard library |
|
95 Python has a very rich standard library of modules. |
|
96 - Few libraries |
|
97 - Math: ~math~, ~random~ |
|
98 - Internet access: ~urllib2~, ~smtplib~ |
|
99 - System, Command line arguments: ~sys~ |
|
100 - Operating system interface: ~os~ |
|
101 - regular expressions: ~re~ |
|
102 - compression: ~gzip~, ~zipfile~, ~tarfile~ |
|
103 - More information |
|
104 - [[http://docs.python.org/library]] |
|
105 * Summary |
|
106 - Running scripts from command line |
|
107 - Learned about modules |
|
108 - importing modules |
|
109 - Python standard library |
|
110 * Thank you! |
|
111 #+begin_latex |
|
112 \begin{block}{} |
|
113 \begin{center} |
|
114 This spoken tutorial has been produced by the |
|
115 \textcolor{blue}{FOSSEE} team, which is funded by the |
|
116 \end{center} |
|
117 \begin{center} |
|
118 \textcolor{blue}{National Mission on Education through \\ |
|
119 Information \& Communication Technology \\ |
|
120 MHRD, Govt. of India}. |
|
121 \end{center} |
|
122 \end{block} |
|
123 #+end_latex |
|
124 |
|
125 |