-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexemples.html
More file actions
214 lines (201 loc) · 12.5 KB
/
exemples.html
File metadata and controls
214 lines (201 loc) · 12.5 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quelques exemples... — Python scientifique - ENS Paris</title>
<link rel="stylesheet" href="_static/nature.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '2013.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/translations.js"></script>
<link rel="top" title="Python scientifique - ENS Paris" href="index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li><a href="index.html">Python scientifique - ENS Paris</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="body">
<div class="section" id="quelques-exemples">
<h1>Quelques exemples...<a class="headerlink" href="#quelques-exemples" title="Lien permanent vers ce titre">¶</a></h1>
<div class="section" id="why-python">
<h2>Why Python?<a class="headerlink" href="#why-python" title="Lien permanent vers ce titre">¶</a></h2>
<div class="section" id="the-scientist-s-needs">
<h3>The scientist’s needs<a class="headerlink" href="#the-scientist-s-needs" title="Lien permanent vers ce titre">¶</a></h3>
<ul class="simple">
<li>Get data (simulation, experiment control)</li>
<li>Manipulate and process data.</li>
<li>Visualize results... to understand what we are doing!</li>
<li>Communicate results: produce figures for reports or publications,
write presentations.</li>
</ul>
</div>
<div class="section" id="specifications">
<h3>Specifications<a class="headerlink" href="#specifications" title="Lien permanent vers ce titre">¶</a></h3>
</div>
<div class="section" id="id1">
<h3>Specifications<a class="headerlink" href="#id1" title="Lien permanent vers ce titre">¶</a></h3>
<ul class="simple">
<li>Rich collection of already existing <strong>bricks</strong> corresponding to classical
numerical methods or basic actions: we don’t want to re-program the
plotting of a curve, a Fourier transform or a fitting algorithm. Don’t
reinvent the wheel!</li>
<li>Easy to learn: computer science is neither our job nor our education. We
want to be able to draw a curve, smooth a signal, do a Fourier transform
in a few minutes.</li>
<li>Easy communication with collaborators, students, customers, to make the code
live within a lab or a company: the code should be as readable as a book.
Thus, the language should contain as few syntax symbols or unneeded routines
as possible that would divert the reader from the mathematical or scientific
understanding of the code.</li>
<li>Efficient code that executes quickly... but needless to say that a very fast
code becomes useless if we spend too much time writing it. So, we need both a
quick development time and a quick execution time.</li>
<li>A single environment/language for everything, if possible, to avoid learning
a new software for each new problem.</li>
</ul>
</div>
</div>
<div class="section" id="scientific-python-building-blocks">
<h2>Scientific Python building blocks<a class="headerlink" href="#scientific-python-building-blocks" title="Lien permanent vers ce titre">¶</a></h2>
<p>Unlike Matlab, Scilab or R, Python does not come with a pre-bundled set
of modules for scientific computing. Below are the basic building blocks
that can be combined to obtain a scientific computing environment:</p>
<ul>
<li><p class="first"><strong>Python</strong>, a generic and modern computing language</p>
<blockquote>
<div><ul class="simple">
<li>Python language: data types (<tt class="docutils literal"><span class="pre">string</span></tt>, <tt class="docutils literal"><span class="pre">int</span></tt>), flow control,
data collections (lists, dictionaries), patterns, etc.</li>
<li>Modules of the standard library.</li>
<li>A large number of specialized modules or applications written in
Python: web protocols, web framework, etc. ... and scientific
computing.</li>
<li>Development tools (automatic testing, documentation generation)</li>
</ul>
</div></blockquote>
<a class="reference internal image-reference" href="_images/snapshot_ipython.png"><img alt="_images/snapshot_ipython.png" class="align-center" src="_images/snapshot_ipython.png" style="width: 316.0px; height: 158.0px;" /></a>
</li>
<li><p class="first"><strong>IPython</strong>, an advanced <strong>Python shell</strong> <a class="reference external" href="http://ipython.scipy.org/moin/">http://ipython.scipy.org/moin/</a></p>
</li>
<li><p class="first"><strong>Numpy</strong> : provides powerful <strong>numerical arrays</strong> objects, and routines to
manipulate them. <a class="reference external" href="http://www.numpy.org/">http://www.numpy.org/</a></p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<div class="newline"></div><span class="gp">>>> </span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<div class="newline"></div><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">8</span><span class="p">])</span>
<div class="newline"></div></pre></div>
</div>
</li>
<li><p class="first"><strong>Scipy</strong> : high-level data processing routines.
Optimization, regression, interpolation, etc <a class="reference external" href="http://www.scipy.org/">http://www.scipy.org/</a></p>
<a class="reference internal image-reference" href="_images/random_c.jpg"><img alt="_images/random_c.jpg" class="align-center" src="_images/random_c.jpg" style="width: 340.0px; height: 210.0px;" /></a>
</li>
<li><p class="first"><strong>Matplotlib</strong> : 2-D visualization, “publication-ready” plots
<a class="reference external" href="http://matplotlib.sourceforge.net/">http://matplotlib.sourceforge.net/</a></p>
</li>
<li><p class="first"><strong>Mayavi</strong> : 3-D visualization
<a class="reference external" href="http://code.enthought.com/projects/mayavi/">http://code.enthought.com/projects/mayavi/</a></p>
</li>
</ul>
</div>
<div class="section" id="the-interactive-workflow-ipython-and-a-text-editor">
<h2>The interactive workflow: IPython and a text editor<a class="headerlink" href="#the-interactive-workflow-ipython-and-a-text-editor" title="Lien permanent vers ce titre">¶</a></h2>
<p><strong>Interactive work to test and understand algorithms:</strong> In this section, we
describe an interactive workflow with <a class="reference external" href="http://ipython.org">IPython</a> that is
handy to explore and understand algorithms.</p>
<p>Python is a general-purpose language. As such, there is not one blessed
environment to work in, and not only one way of using it. Although
this makes it harder for beginners to find their way, it makes it
possible for Python to be used to write programs, in web servers, or
embedded devices.</p>
<div class="admonition note">
<p class="first admonition-title">Remarque</p>
<p>Reference document for this section:</p>
<p class="last"><strong>IPython user manual:</strong> <a class="reference external" href="http://ipython.org/ipython-doc/dev/index.html">http://ipython.org/ipython-doc/dev/index.html</a></p>
</div>
<div class="section" id="command-line-interaction">
<h3>Command line interaction<a class="headerlink" href="#command-line-interaction" title="Lien permanent vers ce titre">¶</a></h3>
<p>Start <cite>ipython</cite>:</p>
<div class="highlight-ipython"><div class="highlight"><pre><span class="gp">In [1]: </span><span class="k">print</span><span class="p">(</span><span class="s">'Hello world'</span><span class="p">)</span>
<div class="newline"></div><span class="go">Hello world</span>
<div class="newline"></div></pre></div>
</div>
<p>Getting help:</p>
<div class="highlight-ipython"><div class="highlight"><pre><span class="gp">In [2]: </span><span class="k">print</span><span class="err">?</span>
<div class="newline"></div><span class="go">Type: builtin_function_or_method</span>
<div class="newline"></div><span class="go">Base Class: <type 'builtin_function_or_method'></span>
<div class="newline"></div><span class="go">String Form: <built-in function print></span>
<div class="newline"></div><span class="go">Namespace: Python builtin</span>
<div class="newline"></div><span class="go">Docstring:</span>
<div class="newline"></div><span class="go"> print(value, ..., sep=' ', end='\n', file=sys.stdout)</span>
<div class="newline"></div>
<div class="newline"></div><span class="go"> Prints the values to a stream, or to sys.stdout by default.</span>
<div class="newline"></div><span class="go"> Optional keyword arguments:</span>
<div class="newline"></div><span class="go"> file: a file-like object (stream); defaults to the current sys.stdout.</span>
<div class="newline"></div><span class="go"> sep: string inserted between values, default a space.</span>
<div class="newline"></div><span class="go"> end: string appended after the last value, default a newline.</span>
<div class="newline"></div></pre></div>
</div>
<p>Create a file <cite>my_file.py</cite> in a text editor. Under EPD (Enthought Python
Distribution), you can use <cite>Scite</cite>, available from the start menu. Under
Python(x,y), you can use Spyder. Under Ubuntu, if you don’t already have your
favorite editor, we would advise installing <cite>Stani’s Python editor</cite>. In the
file, add the following lines:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">s</span> <span class="o">=</span> <span class="s">'Hello world'</span>
<div class="newline"></div><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<div class="newline"></div></pre></div>
</div>
<p>Now, you can run it in IPython and explore the resulting variables:</p>
<div class="highlight-ipython"><div class="highlight"><pre><span class="gp">In [3]: </span><span class="o">%</span><span class="n">run</span> <span class="n">my_file</span><span class="o">.</span><span class="n">py</span>
<div class="newline"></div><span class="go">Hello word</span>
<div class="newline"></div>
<div class="newline"></div><span class="gp">In [4]: </span><span class="n">s</span>
<div class="newline"></div><span class="go">Out[4]: </span><span class="s">'Hello word'</span>
<div class="newline"></div>
<div class="newline"></div><span class="gp">In [5]: </span><span class="o">%</span><span class="n">whos</span>
<div class="newline"></div><span class="go">Variable Type Data/Info</span>
<div class="newline"></div><span class="go">----------------------------</span>
<div class="newline"></div><span class="go">s str Hello word</span>
<div class="newline"></div></pre></div>
</div>
<p><div style="clear: both"></div></p>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li><a href="index.html">Python scientifique - ENS Paris</a> »</li>
</ul>
</div>
<!-- your html code here -->
<a href="http://www.ens.fr"><img src="_static/ENS_Logo.png"
alt="ENS" height="100"></a>
<a href="http://www.inria.fr"><img src="_static/logo-inria.jpg"
alt="INRIA" height="60"></a>
<a href="http://www.saint-gobain-recherche.fr/fr/"><img
src="_static/logoSGR.png" alt="Saint-Gobain Recherche" height="60"></a>
<script language="JavaScript"
src="http://freehostedscripts.net/ocount.php?site=ID1953783&name=pages
visitées"></script>
</body>
</html>