├── README.md
├── ch01-intro.html
├── ch01-intro.ipynb
├── ch01-intro.pdf
├── ch01-intro.py
├── ch02-vectors-matrices-ndarrays.ipynb
├── ch03-symbolic-math-with-sympy.ipynb
├── ch04-plotting-visualization.ipynb
├── ch05-equation-solving.ipynb
├── ch06-optimization.ipynb
├── ch07-interpolation.ipynb
├── ch08-integration.ipynb
├── ch09-ordinary-differential-equations.ipynb
├── ch10-sparse-matrices-graphs.ipynb
├── ch11-fdm-2d-ex1.png
├── ch11-partial-differential-equations.ipynb
├── ch12-data-analysis-pandas-seaborn.ipynb
├── ch13-statistics.ipynb
├── ch14-statistical-modeling.ipynb
├── ch15-machine-learning.ipynb
├── ch16-bayes-statistics.ipynb
├── ch17-signal-processing.ipynb
├── ch18-data-input-output.ipynb
├── ch18-data.csv
├── ch18-data.h5
├── ch18-playerstats-2013-2014-subset.csv
├── ch18-playerstats-2013-2014-top30.csv
├── ch18-playerstats-2013-2014.csv
├── ch18-playerstats-2013-2014.h5
├── ch19-optimization.ipynb
├── cy_cumsum.pyx
├── cy_sum.c
├── cy_sum.cpython-36m-x86_64-linux-gnu.so
├── cy_sum.pyx
├── data.csv
├── data.json
├── european_cities.csv
├── fib.py
├── file1.py
├── file2.py
├── file3.py
├── guitar-echo.wav
├── hello.py
├── pics
├── aggregate-funcs-illustrated.png
├── aggregate-funcs.png
├── arithmetic-ops.png
├── array-funcs.png
├── array-gen-funcs.png
├── array-gen-funcs2.png
├── array-slice-funcs.png
├── autocompletion.png
├── bookcover-2nd-ed.png
├── bookcover-reduced.png
├── bookcover.png
├── broadcasting.png
├── ch08-numerical-integration-example.png
├── ch4-figure-1.pdf
├── ch4-figure-2.pdf
├── conditional-logical-funcs.png
├── constants-specials.png
├── convex-vs-nonconvex.png
├── coupled-damped-oscilators.png
├── dense-vs-sparse.png
├── direction-field-numint.png
├── direction-fields.png
├── direction-graphs-2nd-ex.png
├── dolfin-api-p1.png
├── dolfin-api-p2.png
├── dolfin-mshr-funcs.png
├── element-wise-math-functs.png
├── element-wise-math.png
├── expression-tree.png
├── figures-axes.png
├── font-properties.png
├── graph.pdf
├── graph.png
├── graphtypes-2d.png
├── hypothesis-test-cases.png
├── indexing-viz.png
├── lineprops1.png
├── lineprops2.png
├── lorentz-odes.png
├── matrix-funcs.png
├── networkx-ops.png
├── numerical-error-and-condition-num-vs-p.png
├── numpy-array-index-methods.png
├── patsy-syntax.png
├── plot-types-1.pdf
├── plot-types-2.pdf
├── plot-types-3.pdf
├── plot-types-4.pdf
├── plot-types-5.pdf
├── plot-types-6.pdf
├── plot-types-7.pdf
├── plot-types-8.pdf
├── plot-types-9.pdf
├── predator-prey-populations.png
├── random-var-funcs.png
├── rcm-ordering.png
├── rectangular-linear-equation.png
├── reshape-ops.png
├── set-funcs.png
├── simplifications.png
├── software-stack-overview.png
├── sparse-a-b-tensorprod.png
├── sparse-matrix-representations.png
├── sparse-nz2diags.png
├── sum-by-axis.png
├── symbol-arguments.png
├── symbol-attributes.png
├── sympy-matrix-ops.png
└── tokyo-metro.png
├── setup.py
├── store.h5
├── temperature_indoor_2014.tsv
├── temperature_outdoor_2014.tsv
├── tokyo-metro.json
├── tokyo-metro.msgpack
└── tokyo-metro.pickle
/README.md:
--------------------------------------------------------------------------------
1 | # Numeric Computing with Python, 2nd edition
2 | ### [Original ebook on Apress](https://www.apress.com/us/book/9781484242452)
3 | 
4 |
5 | ### TODO:
6 | - Fix FeniCS installation bugs (Chapter 11)
7 |
8 |
9 |
10 | Chapter | Topics |
11 |
12 |
13 | Intro |
14 | Python, iPython, Jupyter |
15 |
16 |
17 | Intro to NumPy |
18 | Arrays: Create, Index, Slice, Reshape, Resize, Vectorized ops, Matrix & Vector ops |
19 |
20 |
21 | Intro to SymPy |
22 | Symbols, Expressions, Manipulations, Calculus, Equations, Linear Algebra |
23 |
24 |
25 | Plotting & Visualization Intro to Matplotlib |
26 | Plots, Steps, Bargraphs, Histograms, ErrorBars, ScatterPlots, Fill_Between, QuiverPlots, ColorMaps, 3D Plots |
27 |
28 |
29 | Equation Solvers with SciPy |
30 | Linear Equations (square, rectangular), Eigenvalues, NonLinear Equations |
31 |
32 |
33 | Optimization with SciPy |
34 | Univariate, Multivariate (unconstrained), Nonlinear Least Squares, Constrained |
35 |
36 |
37 | Interpolation with SciPy |
38 | Polynomials, Splines, Multivariate |
39 |
40 |
41 | Integration with SciPy & Scikit-monaco |
42 | Numerical Methods, Multiple integration, Symbolic & arbitrary precision, Integral transforms |
43 |
44 |
45 | Ordinary Differential Equations (ODEs) |
46 | Direction fields, Laplace transforms, Numerical methods |
47 |
48 |
49 | Sparse Matrices & Graphs |
50 | Matrix ops, Linear equation systems incl. Eigenvalues, Graphs/Networks |
51 |
52 |
53 | Partial Differential Equations (PDEs) |
54 | Finite-difference methods, Finite element methods & libraries, PDE solvers with FEniCS |
55 |
56 |
57 | Data Analysis with Pandas & Seaborn |
58 | Series, DataFrames, TimeSeries |
59 |
60 |
61 | Statistics with SciPy & NumPy |
62 | Probability, Random numbers, Distributions, Hypothesis testing, Nonparametric methods |
63 |
64 |
65 | Statistical Modeling with Stasmodels & Patsy |
66 | Model definitions, Linear regression, Logistic regression, Poisson models, Time series |
67 |
68 |
69 | Intro to Machine Learning with scikit-learn |
70 | Concepts, Regression, Classification, Clustering |
71 |
72 |
73 | Bayesian Statistics with pyMC |
74 | Concepts, Sampling posterior distributions, Linear regression |
75 |
76 |
77 | Signal Processing with SciPy, fftpack, signal, wavfile & io |
78 | Spectral analysis (Fourier transforms, windows, spectrograms), Signal filters (Convolution, FIR/IIR filters) |
79 |
80 |
81 | Data I/O |
82 | CSV, HDF5 (h5py files, groups, datasets, attributes, PyTables, HDFStore), JSON, Serialization |
83 |
84 |
85 | Code optimization |
86 | Numba, Cython |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/ch01-intro.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "### Chapter 1: Computing with Python"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "### Overview: a typical Python-based scientific computing stack.\n",
15 | "\n",
16 | "\n",
17 | "### Resources:\n",
18 | "- [Intel MKL (Math Kernel Library)](https://software.intel.com/en-us/intel-mkl)\n",
19 | "- [openBLAS](https://www.openblas.net)\n",
20 | "- [ATLAS](https://math-atlas.sourceforge.net)\n",
21 | "- [SciPy](http://www.scipy.org)\n",
22 | "- [Python Numeric & Scientific topics](http://wiki.python.org/moin/NumericAndScientific)"
23 | ]
24 | },
25 | {
26 | "cell_type": "markdown",
27 | "metadata": {},
28 | "source": [
29 | "### Interpreter\n",
30 | "- The easist way to execute Python code: run the program directly.\n",
31 | "- Use Jupyter magic command to write Python source file to disk:"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": 1,
37 | "metadata": {},
38 | "outputs": [
39 | {
40 | "name": "stdout",
41 | "output_type": "stream",
42 | "text": [
43 | "Overwriting hello.py\n"
44 | ]
45 | }
46 | ],
47 | "source": [
48 | "%%writefile hello.py\n",
49 | "print(\"Hello from Python!\")"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "* Use the ! system shell command (included in the Python Jupyter kernel) to interactively run Python with hello.py as its argument."
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 2,
62 | "metadata": {},
63 | "outputs": [
64 | {
65 | "name": "stdout",
66 | "output_type": "stream",
67 | "text": [
68 | "Hello from Python!\n"
69 | ]
70 | }
71 | ],
72 | "source": [
73 | "!python3 hello.py"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": 3,
79 | "metadata": {},
80 | "outputs": [
81 | {
82 | "name": "stdout",
83 | "output_type": "stream",
84 | "text": [
85 | "Python 3.11.4\n"
86 | ]
87 | }
88 | ],
89 | "source": [
90 | "!python3 --version"
91 | ]
92 | },
93 | {
94 | "cell_type": "markdown",
95 | "metadata": {},
96 | "source": [
97 | "### Input and output caching\n",
98 | "\n",
99 | "* Input & output history can be accessed using __In__ (a list) & __Out__ (a dictionary). Both can be indexed with a cell number. "
100 | ]
101 | },
102 | {
103 | "cell_type": "code",
104 | "execution_count": 4,
105 | "metadata": {},
106 | "outputs": [
107 | {
108 | "data": {
109 | "text/plain": [
110 | "'get_ipython().run_cell_magic(\\'writefile\\', \\'hello.py\\', \\'print(\"Hello from Python!\")\\\\n\\')'"
111 | ]
112 | },
113 | "execution_count": 4,
114 | "metadata": {},
115 | "output_type": "execute_result"
116 | }
117 | ],
118 | "source": [
119 | "3*3\n",
120 | "In[1]"
121 | ]
122 | },
123 | {
124 | "cell_type": "markdown",
125 | "metadata": {},
126 | "source": [
127 | "* A single underscore = the most recent output; \n",
128 | "* A double underscore = the _next_ most recent output."
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": 5,
134 | "metadata": {},
135 | "outputs": [
136 | {
137 | "data": {
138 | "text/plain": [
139 | "2"
140 | ]
141 | },
142 | "execution_count": 5,
143 | "metadata": {},
144 | "output_type": "execute_result"
145 | }
146 | ],
147 | "source": [
148 | "1+1"
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "execution_count": 6,
154 | "metadata": {},
155 | "outputs": [
156 | {
157 | "data": {
158 | "text/plain": [
159 | "4"
160 | ]
161 | },
162 | "execution_count": 6,
163 | "metadata": {},
164 | "output_type": "execute_result"
165 | }
166 | ],
167 | "source": [
168 | "2+2"
169 | ]
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": 7,
174 | "metadata": {},
175 | "outputs": [
176 | {
177 | "data": {
178 | "text/plain": [
179 | "(4, 2)"
180 | ]
181 | },
182 | "execution_count": 7,
183 | "metadata": {},
184 | "output_type": "execute_result"
185 | }
186 | ],
187 | "source": [
188 | "_, __"
189 | ]
190 | },
191 | {
192 | "cell_type": "code",
193 | "execution_count": 8,
194 | "metadata": {},
195 | "outputs": [
196 | {
197 | "data": {
198 | "text/plain": [
199 | "['',\n",
200 | " 'get_ipython().run_cell_magic(\\'writefile\\', \\'hello.py\\', \\'print(\"Hello from Python!\")\\\\n\\')',\n",
201 | " \"get_ipython().system('python3 hello.py')\",\n",
202 | " \"get_ipython().system('python3 --version')\",\n",
203 | " '3*3\\nIn[1]',\n",
204 | " '1+1',\n",
205 | " '2+2',\n",
206 | " '_, __',\n",
207 | " '# In = a list\\nIn']"
208 | ]
209 | },
210 | "execution_count": 8,
211 | "metadata": {},
212 | "output_type": "execute_result"
213 | }
214 | ],
215 | "source": [
216 | "# In = a list\n",
217 | "In"
218 | ]
219 | },
220 | {
221 | "cell_type": "code",
222 | "execution_count": 9,
223 | "metadata": {},
224 | "outputs": [
225 | {
226 | "data": {
227 | "text/plain": [
228 | "{4: 'get_ipython().run_cell_magic(\\'writefile\\', \\'hello.py\\', \\'print(\"Hello from Python!\")\\\\n\\')',\n",
229 | " 5: 2,\n",
230 | " 6: 4,\n",
231 | " 7: (4, 2),\n",
232 | " 8: ['',\n",
233 | " 'get_ipython().run_cell_magic(\\'writefile\\', \\'hello.py\\', \\'print(\"Hello from Python!\")\\\\n\\')',\n",
234 | " \"get_ipython().system('python3 hello.py')\",\n",
235 | " \"get_ipython().system('python3 --version')\",\n",
236 | " '3*3\\nIn[1]',\n",
237 | " '1+1',\n",
238 | " '2+2',\n",
239 | " '_, __',\n",
240 | " '# In = a list\\nIn',\n",
241 | " '# Out = a dictionary\\nOut']}"
242 | ]
243 | },
244 | "execution_count": 9,
245 | "metadata": {},
246 | "output_type": "execute_result"
247 | }
248 | ],
249 | "source": [
250 | "# Out = a dictionary\n",
251 | "Out"
252 | ]
253 | },
254 | {
255 | "cell_type": "code",
256 | "execution_count": 10,
257 | "metadata": {},
258 | "outputs": [],
259 | "source": [
260 | "# Suppress output results by ending statement with a semicolon\n",
261 | "1+2;"
262 | ]
263 | },
264 | {
265 | "cell_type": "markdown",
266 | "metadata": {},
267 | "source": [
268 | "### Autocompletion\n",
269 | "\n",
270 | "* The __Tab__ key activates autocompletion (displays list of symbol names that are valid completions of what has been typed thus far.)"
271 | ]
272 | },
273 | {
274 | "cell_type": "code",
275 | "execution_count": 11,
276 | "metadata": {},
277 | "outputs": [],
278 | "source": [
279 | "import os"
280 | ]
281 | },
282 | {
283 | "cell_type": "markdown",
284 | "metadata": {},
285 | "source": [
286 | "* Results of typing \"os.w\", followed by \\t:\n",
287 | "\n",
288 | ""
289 | ]
290 | },
291 | {
292 | "cell_type": "markdown",
293 | "metadata": {},
294 | "source": [
295 | "### Documentation\n",
296 | "\n",
297 | "* \"Docstrings\" provide a built-in reference manual for most Python modules. Display the docstring by appending a Python object with \"?\"."
298 | ]
299 | },
300 | {
301 | "cell_type": "code",
302 | "execution_count": 12,
303 | "metadata": {},
304 | "outputs": [
305 | {
306 | "data": {
307 | "text/plain": [
308 | "\u001b[0;31mSignature:\u001b[0m \u001b[0mmath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m/\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
309 | "\u001b[0;31mDocstring:\u001b[0m Return the cosine of x (measured in radians).\n",
310 | "\u001b[0;31mType:\u001b[0m builtin_function_or_method"
311 | ]
312 | },
313 | "metadata": {},
314 | "output_type": "display_data"
315 | }
316 | ],
317 | "source": [
318 | "import math\n",
319 | "math.cos?"
320 | ]
321 | },
322 | {
323 | "cell_type": "markdown",
324 | "metadata": {},
325 | "source": [
326 | "### Interaction with System Shell\n",
327 | "\n",
328 | "* Anything after ! is evaluated using the system shell, such as bash.\n",
329 | "* (I use Ubuntu Linux as my laptop OS. Your Windows equivalents will vary.)"
330 | ]
331 | },
332 | {
333 | "cell_type": "code",
334 | "execution_count": 13,
335 | "metadata": {},
336 | "outputs": [
337 | {
338 | "name": "stdout",
339 | "output_type": "stream",
340 | "text": [
341 | "file1.py file2.py file3.py\n"
342 | ]
343 | }
344 | ],
345 | "source": [
346 | "!touch file1.py file2.py file3.py\n",
347 | "!ls file*"
348 | ]
349 | },
350 | {
351 | "cell_type": "code",
352 | "execution_count": 14,
353 | "metadata": {},
354 | "outputs": [
355 | {
356 | "name": "stdout",
357 | "output_type": "stream",
358 | "text": [
359 | "3\n",
360 | "['file1.py', 'file2.py', 'file3.py']\n"
361 | ]
362 | }
363 | ],
364 | "source": [
365 | "# output of a system shell command can be captured in a Python variable\n",
366 | "files = !ls file*\n",
367 | "print(len(files))\n",
368 | "print(files)"
369 | ]
370 | },
371 | {
372 | "cell_type": "code",
373 | "execution_count": 15,
374 | "metadata": {},
375 | "outputs": [
376 | {
377 | "name": "stdout",
378 | "output_type": "stream",
379 | "text": [
380 | "-rw-rw-r-- 1 bjpcjp bjpcjp 0 Nov 14 08:18 file1.py\n"
381 | ]
382 | }
383 | ],
384 | "source": [
385 | "# pass Python variable values to shell commands\n",
386 | "# by prefixing the variable name with $.\n",
387 | "file = \"file1.py\"\n",
388 | "!ls -l $file"
389 | ]
390 | },
391 | {
392 | "cell_type": "markdown",
393 | "metadata": {},
394 | "source": [
395 | "### IPython Extensions\n",
396 | "\n",
397 | "* Commands start with one or two \"%\" characters. A single % is used for single-line commands; dual %% is used for cells (multiple lines).\n",
398 | "\n",
399 | "* `%lsmagic` returns a list of available commands."
400 | ]
401 | },
402 | {
403 | "cell_type": "code",
404 | "execution_count": 16,
405 | "metadata": {},
406 | "outputs": [
407 | {
408 | "data": {
409 | "application/json": {
410 | "cell": {
411 | "!": "OSMagics",
412 | "HTML": "Other",
413 | "SVG": "Other",
414 | "bash": "Other",
415 | "capture": "ExecutionMagics",
416 | "code_wrap": "ExecutionMagics",
417 | "debug": "ExecutionMagics",
418 | "file": "Other",
419 | "html": "DisplayMagics",
420 | "javascript": "DisplayMagics",
421 | "js": "DisplayMagics",
422 | "latex": "DisplayMagics",
423 | "markdown": "DisplayMagics",
424 | "perl": "Other",
425 | "prun": "ExecutionMagics",
426 | "pypy": "Other",
427 | "python": "Other",
428 | "python2": "Other",
429 | "python3": "Other",
430 | "ruby": "Other",
431 | "script": "ScriptMagics",
432 | "sh": "Other",
433 | "svg": "DisplayMagics",
434 | "sx": "OSMagics",
435 | "system": "OSMagics",
436 | "time": "ExecutionMagics",
437 | "timeit": "ExecutionMagics",
438 | "writefile": "OSMagics"
439 | },
440 | "line": {
441 | "alias": "OSMagics",
442 | "alias_magic": "BasicMagics",
443 | "autoawait": "AsyncMagics",
444 | "autocall": "AutoMagics",
445 | "automagic": "AutoMagics",
446 | "autosave": "KernelMagics",
447 | "bookmark": "OSMagics",
448 | "cat": "Other",
449 | "cd": "OSMagics",
450 | "clear": "KernelMagics",
451 | "code_wrap": "ExecutionMagics",
452 | "colors": "BasicMagics",
453 | "conda": "PackagingMagics",
454 | "config": "ConfigMagics",
455 | "connect_info": "KernelMagics",
456 | "cp": "Other",
457 | "debug": "ExecutionMagics",
458 | "dhist": "OSMagics",
459 | "dirs": "OSMagics",
460 | "doctest_mode": "BasicMagics",
461 | "ed": "Other",
462 | "edit": "KernelMagics",
463 | "env": "OSMagics",
464 | "gui": "BasicMagics",
465 | "hist": "Other",
466 | "history": "HistoryMagics",
467 | "killbgscripts": "ScriptMagics",
468 | "ldir": "Other",
469 | "less": "KernelMagics",
470 | "lf": "Other",
471 | "lk": "Other",
472 | "ll": "Other",
473 | "load": "CodeMagics",
474 | "load_ext": "ExtensionMagics",
475 | "loadpy": "CodeMagics",
476 | "logoff": "LoggingMagics",
477 | "logon": "LoggingMagics",
478 | "logstart": "LoggingMagics",
479 | "logstate": "LoggingMagics",
480 | "logstop": "LoggingMagics",
481 | "ls": "Other",
482 | "lsmagic": "BasicMagics",
483 | "lx": "Other",
484 | "macro": "ExecutionMagics",
485 | "magic": "BasicMagics",
486 | "mamba": "PackagingMagics",
487 | "man": "KernelMagics",
488 | "matplotlib": "PylabMagics",
489 | "micromamba": "PackagingMagics",
490 | "mkdir": "Other",
491 | "more": "KernelMagics",
492 | "mv": "Other",
493 | "notebook": "BasicMagics",
494 | "page": "BasicMagics",
495 | "pastebin": "CodeMagics",
496 | "pdb": "ExecutionMagics",
497 | "pdef": "NamespaceMagics",
498 | "pdoc": "NamespaceMagics",
499 | "pfile": "NamespaceMagics",
500 | "pinfo": "NamespaceMagics",
501 | "pinfo2": "NamespaceMagics",
502 | "pip": "PackagingMagics",
503 | "popd": "OSMagics",
504 | "pprint": "BasicMagics",
505 | "precision": "BasicMagics",
506 | "prun": "ExecutionMagics",
507 | "psearch": "NamespaceMagics",
508 | "psource": "NamespaceMagics",
509 | "pushd": "OSMagics",
510 | "pwd": "OSMagics",
511 | "pycat": "OSMagics",
512 | "pylab": "PylabMagics",
513 | "qtconsole": "KernelMagics",
514 | "quickref": "BasicMagics",
515 | "recall": "HistoryMagics",
516 | "rehashx": "OSMagics",
517 | "reload_ext": "ExtensionMagics",
518 | "rep": "Other",
519 | "rerun": "HistoryMagics",
520 | "reset": "NamespaceMagics",
521 | "reset_selective": "NamespaceMagics",
522 | "rm": "Other",
523 | "rmdir": "Other",
524 | "run": "ExecutionMagics",
525 | "save": "CodeMagics",
526 | "sc": "OSMagics",
527 | "set_env": "OSMagics",
528 | "store": "StoreMagics",
529 | "sx": "OSMagics",
530 | "system": "OSMagics",
531 | "tb": "ExecutionMagics",
532 | "time": "ExecutionMagics",
533 | "timeit": "ExecutionMagics",
534 | "unalias": "OSMagics",
535 | "unload_ext": "ExtensionMagics",
536 | "who": "NamespaceMagics",
537 | "who_ls": "NamespaceMagics",
538 | "whos": "NamespaceMagics",
539 | "xdel": "NamespaceMagics",
540 | "xmode": "BasicMagics"
541 | }
542 | },
543 | "text/plain": [
544 | "Available line magics:\n",
545 | "%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %code_wrap %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %mamba %man %matplotlib %micromamba %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n",
546 | "\n",
547 | "Available cell magics:\n",
548 | "%%! %%HTML %%SVG %%bash %%capture %%code_wrap %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n",
549 | "\n",
550 | "Automagic is ON, % prefix IS NOT needed for line magics."
551 | ]
552 | },
553 | "execution_count": 16,
554 | "metadata": {},
555 | "output_type": "execute_result"
556 | }
557 | ],
558 | "source": [
559 | "%lsmagic"
560 | ]
561 | },
562 | {
563 | "cell_type": "markdown",
564 | "metadata": {},
565 | "source": [
566 | "### Running scripts\n",
567 | "\n",
568 | "- `%run` executes an external Python source file within an interactive IPython session."
569 | ]
570 | },
571 | {
572 | "cell_type": "code",
573 | "execution_count": 17,
574 | "metadata": {},
575 | "outputs": [
576 | {
577 | "name": "stdout",
578 | "output_type": "stream",
579 | "text": [
580 | "Overwriting fib.py\n"
581 | ]
582 | }
583 | ],
584 | "source": [
585 | "%%writefile fib.py\n",
586 | "\n",
587 | "def fib(N): \n",
588 | " \"\"\" \n",
589 | " Return a list of the first N Fibonacci numbers.\n",
590 | " \"\"\" \n",
591 | " f0, f1 = 0, 1\n",
592 | " f = [1] * N\n",
593 | " for n in range(1, N):\n",
594 | " f[n] = f0 + f1\n",
595 | " f0, f1 = f1, f[n]\n",
596 | "\n",
597 | " return f\n",
598 | "\n",
599 | "print(fib(10))"
600 | ]
601 | },
602 | {
603 | "cell_type": "code",
604 | "execution_count": 18,
605 | "metadata": {},
606 | "outputs": [
607 | {
608 | "name": "stdout",
609 | "output_type": "stream",
610 | "text": [
611 | "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n"
612 | ]
613 | }
614 | ],
615 | "source": [
616 | "!python3 fib.py"
617 | ]
618 | },
619 | {
620 | "cell_type": "code",
621 | "execution_count": 19,
622 | "metadata": {},
623 | "outputs": [
624 | {
625 | "name": "stdout",
626 | "output_type": "stream",
627 | "text": [
628 | "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]\n"
629 | ]
630 | }
631 | ],
632 | "source": [
633 | "%run fib.py"
634 | ]
635 | },
636 | {
637 | "cell_type": "code",
638 | "execution_count": 20,
639 | "metadata": {},
640 | "outputs": [
641 | {
642 | "data": {
643 | "text/plain": [
644 | "[1, 1, 2, 3, 5, 8]"
645 | ]
646 | },
647 | "execution_count": 20,
648 | "metadata": {},
649 | "output_type": "execute_result"
650 | }
651 | ],
652 | "source": [
653 | "fib(6)"
654 | ]
655 | },
656 | {
657 | "cell_type": "markdown",
658 | "metadata": {},
659 | "source": [
660 | "## Listing all defined symbols\n",
661 | "\n",
662 | "* `%who` lists all defined symbols\n",
663 | "* `%whos` provides more detailed info."
664 | ]
665 | },
666 | {
667 | "cell_type": "code",
668 | "execution_count": 21,
669 | "metadata": {},
670 | "outputs": [
671 | {
672 | "name": "stdout",
673 | "output_type": "stream",
674 | "text": [
675 | "fib\t file\t files\t math\t os\t \n"
676 | ]
677 | }
678 | ],
679 | "source": [
680 | "%who"
681 | ]
682 | },
683 | {
684 | "cell_type": "code",
685 | "execution_count": 22,
686 | "metadata": {},
687 | "outputs": [
688 | {
689 | "name": "stdout",
690 | "output_type": "stream",
691 | "text": [
692 | "Variable Type Data/Info\n",
693 | "--------------------------------\n",
694 | "fib function