Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit ea4715f7 authored by Loic Huder's avatar Loic Huder
Browse files

Fixed typos in pres110

parent 85fa4f64
......@@ -12,7 +12,7 @@
"\n",
"**A training to acquire strong basis in Python to use it efficiently**\n",
"\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Oliver Henriot (GRICAD), Christophe Picard (LJK)\n",
"Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Oliver Henriot (GRICAD), Christophe Picard (LJK), Loïc Huder (ISTerre)\n",
"\n",
"# Python scientific ecosystem\n",
"# A short introduction to Numpy, Scipy and Pandas"
......@@ -33,9 +33,9 @@
"- [scipy](http://www.scipy.org/): high-level numerical routines. Optimization, regression, interpolation, etc.\n",
"- [matplotlib](http://matplotlib.org/): 2D-3D visualization, “publication-ready” plots.\n",
"\n",
"With `Ipython` and `Spyder`, Python plus these fundamental scientifics packages constitute a very good alternative to Matlab. Matlab and this Python ecosystem are technically very similar (using the libraries Blas and Lapack). Python syntax is nicer and this language is much more generalist. Matlab has a JIT compiler so other Python tools (for example `pypy`, `cython`, `numba`, `pythran`, `theano`...) have to be used to optimize the code to reach the performance of optimized Matlab code.\n",
"With `IPython` and `Spyder`, Python plus these fundamental scientific packages constitutes a very good alternative to Matlab, that is technically very similar (using the libraries Blas and Lapack). Matlab has a JustInTime (JIT) compiler so that Matlab code is generally faster than Python. However, we will see that Numpy is already quite efficient for standard operations and other Python tools (for example `pypy`, `cython`, `numba`, `pythran`, `theano`...) can be used to optimize the code to reach the performance of optimized Matlab code.\n",
"\n",
"There are several other scientific Python packages (see our notebook `pres13_doc_applications.ipynb`)."
"The advantage of Python over Matlab is its high polyvalency (and nicer syntax) and there are notably several other scientific Python packages (see our notebook `pres13_doc_applications.ipynb`):"
]
},
{
......@@ -67,9 +67,9 @@
}
},
"source": [
"## A short introduction on Numpy\n",
"## A short introduction on NumPy\n",
"\n",
"Code using numpy usually starts with the import statement"
"Code using `numpy` usually starts with the import statement"
]
},
{
......@@ -85,7 +85,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy provides the type `np.ndarray`. Such array are multidimensionnal sequences of homogeneous elements. They can be created for example with the commands:"
"NumPy provides the type `np.ndarray`. Such array are multidimensionnal sequences of homogeneous elements. They can be created for example with the commands:"
]
},
{
......@@ -118,7 +118,7 @@
{
"data": {
"text/plain": [
"array([1.07312086e-316, 0.00000000e+000, 5.41759977e-317, 6.93318354e-310])"
"array([1.57244415e-316, 0.00000000e+000, 1.57476745e-316, 4.45619116e-313])"
]
},
"execution_count": 3,
......@@ -258,7 +258,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A numpy array can be easily converted to a Python list."
"A NumPy array can be easily converted to a Python list."
]
},
{
......@@ -290,8 +290,8 @@
}
},
"source": [
"# Numpy efficiency\n",
"Beside some convenient functions for the manipulation of data in arrays of arbritrary dimensions, numpy can be much more efficient than pure Python."
"# NumPy efficiency\n",
"Beside some convenient functions for the manipulation of data in arrays of arbritrary dimensions, `numpy` can be much more efficient than pure Python."
]
},
{
......@@ -303,7 +303,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"13.4 µs ± 1.61 µs per loop (mean ± std. dev. of 7 runs, 100000 loops each)\n"
"15.6 µs ± 1.8 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
......@@ -375,11 +375,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"11.9 us +- 437 ns per loop (mean +- std. dev. of 7 runs, 100000 loops each)\n",
"12.9 us +- 2.03 us per loop (mean +- std. dev. of 7 runs, 100000 loops each)\n",
"\n",
"1.34 us +- 93.9 ns per loop (mean +- std. dev. of 7 runs, 1000000 loops each)\n",
"1.25 us +- 54.2 ns per loop (mean +- std. dev. of 7 runs, 1000000 loops each)\n",
"\n",
"Creation of object: ratio times (Python / NumPy): 8.880597014925373\n"
"Creation of object: ratio times (Python / NumPy): 10.32\n"
]
}
],
......@@ -422,7 +422,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"20.2 ms +- 2.77 ms per loop (mean +- std. dev. of 7 runs, 10 loops each)\n",
"16.3 ms +- 941 us per loop (mean +- std. dev. of 7 runs, 100 loops each)\n",
"\n"
]
}
......@@ -452,7 +452,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"207 us +- 15 us per loop (mean +- std. dev. of 7 runs, 1000 loops each)\n",
"229 us +- 10.3 us per loop (mean +- std. dev. of 7 runs, 1000 loops each)\n",
"\n"
]
}
......@@ -470,11 +470,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"20.2 ms +- 2.77 ms per loop (mean +- std. dev. of 7 runs, 10 loops each)\n",
"16.3 ms +- 941 us per loop (mean +- std. dev. of 7 runs, 100 loops each)\n",
"\n",
"207 us +- 15 us per loop (mean +- std. dev. of 7 runs, 1000 loops each)\n",
"229 us +- 10.3 us per loop (mean +- std. dev. of 7 runs, 1000 loops each)\n",
"\n",
"Additions: ratio times (Python / NumPy): 97.58454106280193\n"
"Additions: ratio times (Python / NumPy): 71.17903930131006\n"
]
}
],
......@@ -497,7 +497,7 @@
}
},
"source": [
"# Manipulating numpy arrays"
"# Manipulating NumPy arrays"
]
},
{
......@@ -512,19 +512,19 @@
},
{
"cell_type": "code",
"execution_count": 69,
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.6642251 , 0.81037275, 0.82464498, 0.03382786, 0.52260623],\n",
" [0.29404821, 0.59309748, 0.1408015 , 0.24315286, 0.02499713],\n",
" [0.67212693, 0.66863594, 0.61845366, 0.21243744, 0.84314157],\n",
" [0.40933625, 0.77076404, 0.48664432, 0.5823091 , 0.45242895]])"
"array([[0.02575104, 0.41016966, 0.87184936, 0.00965157, 0.96352153],\n",
" [0.02474661, 0.12216842, 0.95490852, 0.15880049, 0.76064248],\n",
" [0.01281296, 0.73360358, 0.24703428, 0.6335245 , 0.3614144 ],\n",
" [0.30331006, 0.48273018, 0.96294812, 0.1527062 , 0.52671139]])"
]
},
"execution_count": 69,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
......@@ -536,16 +536,16 @@
},
{
"cell_type": "code",
"execution_count": 70,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.2940482110988186"
"0.024746607658785114"
]
},
"execution_count": 70,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
......@@ -557,17 +557,17 @@
},
{
"cell_type": "code",
"execution_count": 71,
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.6642251 , 0.81037275, 0.82464498, 0.03382786, 0.52260623],\n",
" [0.29404821, 0.59309748, 0.1408015 , 0.24315286, 0.02499713]])"
"array([[0.02575104, 0.41016966, 0.87184936, 0.00965157, 0.96352153],\n",
" [0.02474661, 0.12216842, 0.95490852, 0.15880049, 0.76064248]])"
]
},
"execution_count": 71,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
......@@ -579,16 +579,16 @@
},
{
"cell_type": "code",
"execution_count": 72,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.52260623, 0.02499713, 0.84314157, 0.45242895])"
"array([0.96352153, 0.76064248, 0.3614144 , 0.52671139])"
]
},
"execution_count": 72,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
......@@ -600,17 +600,17 @@
},
{
"cell_type": "code",
"execution_count": 73,
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.6642251 , 0.82464498, 0.52260623],\n",
" [0.29404821, 0.1408015 , 0.02499713]])"
"array([[0.02575104, 0.87184936, 0.96352153],\n",
" [0.02474661, 0.95490852, 0.76064248]])"
]
},
"execution_count": 73,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
......@@ -629,19 +629,19 @@
},
{
"cell_type": "code",
"execution_count": 74,
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ True True True False True]\n",
" [False True False False False]\n",
" [ True True True False True]\n",
" [False True False True False]]\n",
"[0.6642251 0.81037275 0.82464498 0.52260623 0.59309748 0.67212693\n",
" 0.66863594 0.61845366 0.84314157 0.77076404 0.5823091 ]\n"
"[[False False True False True]\n",
" [False False True False True]\n",
" [False True False True False]\n",
" [False False True False True]]\n",
"[0.87184936 0.96352153 0.95490852 0.76064248 0.73360358 0.6335245\n",
" 0.96294812 0.52671139]\n"
]
}
],
......@@ -660,19 +660,19 @@
},
{
"cell_type": "code",
"execution_count": 75,
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[32.08344593, 33.76043147, 33.92648913, 25.33942296, 30.49917958],\n",
" [28.02694646, 31.28273947, 26.4278401 , 27.49065188, 25.2505962 ],\n",
" [32.17302392, 32.13343338, 31.56702157, 27.16950403, 34.14230335],\n",
" [29.2609187 , 33.30171766, 30.10326586, 31.16217489, 29.7289815 ]])"
"array([[25.25817356, 29.26993578, 34.47861492, 25.0966089 , 35.563589 ],\n",
" [25.24807847, 26.23660929, 35.46093547, 26.61322249, 33.18500177],\n",
" [25.12829382, 32.87420996, 27.53136869, 31.7365983 , 28.74476441],\n",
" [28.12509756, 30.06033028, 35.5567503 , 26.55038118, 30.54453883]])"
]
},
"execution_count": 75,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
......@@ -690,19 +690,19 @@
},
{
"cell_type": "code",
"execution_count": 76,
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1.94298431, 2.24874605, 2.28107079, 1.03440653, 1.68641712],\n",
" [1.34184859, 1.8095849 , 1.15119612, 1.27526354, 1.02531218],\n",
" [1.95839827, 1.95157343, 1.85605573, 1.23668874, 2.32365544],\n",
" [1.50581797, 2.16141704, 1.62684786, 1.79016734, 1.57212617]])"
"array([[1.02608547, 1.50707346, 2.3913292 , 1.0096983 , 2.62090984],\n",
" [1.02505535, 1.12994439, 2.59843286, 1.17210408, 2.13965046],\n",
" [1.0128954 , 2.08257181, 1.28022299, 1.88423989, 1.43535816],\n",
" [1.35433432, 1.62049261, 2.61940743, 1.16498266, 1.69335437]])"
]
},
"execution_count": 76,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
......@@ -720,17 +720,17 @@
},
{
"cell_type": "code",
"execution_count": 77,
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0. 0.81037275 0.82464498 0.03382786 0.52260623]\n",
" [0. 0.59309748 0.1408015 0.24315286 0.02499713]\n",
" [0. 0.66863594 0.61845366 0.21243744 0.84314157]\n",
" [0. 0.77076404 0.48664432 0.5823091 0.45242895]]\n"
"[[0. 0.41016966 0.87184936 0.00965157 0.96352153]\n",
" [0. 0.12216842 0.95490852 0.15880049 0.76064248]\n",
" [0. 0.73360358 0.24703428 0.6335245 0.3614144 ]\n",
" [0. 0.48273018 0.96294812 0.1527062 0.52671139]]\n"
]
}
],
......@@ -741,17 +741,17 @@
},
{
"cell_type": "code",
"execution_count": 78,
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0. 1.23400004 1.21264305 29.56142899 1.91348656]\n",
" [ 0. 1.68606347 7.10219689 4.11263932 40.00458583]\n",
" [ 0. 1.49558219 1.61693601 4.70726825 1.18604045]\n",
" [ 0. 1.29741392 2.05488889 1.717301 2.21029178]]\n"
"[[ 0. 2.43801551 1.14698713 103.61003706 1.03785953]\n",
" [ 0. 8.18542165 1.04722073 6.29720982 1.31467809]\n",
" [ 0. 1.36313403 4.04802126 1.57847092 2.76690688]\n",
" [ 0. 2.07155059 1.03847754 6.54852262 1.89857294]]\n"
]
}
],
......@@ -766,12 +766,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Attributes and methods of np.ndarray (see the [doc](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray))"
"### Attributes and methods of `np.ndarray` (see the [doc](https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray))"
]
},
{
"cell_type": "code",
"execution_count": 79,
"execution_count": 31,
"metadata": {},
"outputs": [
{
......@@ -788,20 +788,20 @@
},
{
"cell_type": "code",
"execution_count": 80,
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0. 1.23400004 1.21264305 29.56142899 1.91348656]\n",
" [ 0. 1.68606347 7.10219689 4.11263932 40.00458583]\n",
" [ 0. 1.49558219 1.61693601 4.70726825 1.18604045]\n",
" [ 0. 1.29741392 2.05488889 1.717301 2.21029178]]\n",
"Mean value 5.155638331549335\n",
"Mean line [ 0. 1.4282649 2.99666621 10.02465939 11.32860116]\n",
"Mean column [ 6.78431173 10.5810971 1.80116538 1.45597912]\n"
"[[ 0. 2.43801551 1.14698713 103.61003706 1.03785953]\n",
" [ 0. 8.18542165 1.04722073 6.29720982 1.31467809]\n",
" [ 0. 1.36313403 4.04802126 1.57847092 2.76690688]\n",
" [ 0. 2.07155059 1.03847754 6.54852262 1.89857294]]\n",
"Mean value 7.319554315640504\n",
"Mean line [ 0. 3.51453045 1.82017667 29.5085601 1.75450436]\n",
"Mean column [21.64657985 3.36890606 1.95130662 2.31142474]\n"
]
}
],
......@@ -815,21 +815,21 @@
},
{
"cell_type": "code",
"execution_count": 81,
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0. 1.23400004 1.21264305 29.56142899 1.91348656]\n",
" [ 0. 1.68606347 7.10219689 4.11263932 40.00458583]\n",
" [ 0. 1.49558219 1.61693601 4.70726825 1.18604045]\n",
" [ 0. 1.29741392 2.05488889 1.717301 2.21029178]] (4, 5)\n",
"[ 0. 1.23400004 1.21264305 29.56142899 1.91348656 0.\n",
" 1.68606347 7.10219689 4.11263932 40.00458583 0. 1.49558219\n",
" 1.61693601 4.70726825 1.18604045 0. 1.29741392 2.05488889\n",
" 1.717301 2.21029178] (20,)\n"
"[[ 0. 2.43801551 1.14698713 103.61003706 1.03785953]\n",
" [ 0. 8.18542165 1.04722073 6.29720982 1.31467809]\n",
" [ 0. 1.36313403 4.04802126 1.57847092 2.76690688]\n",
" [ 0. 2.07155059 1.03847754 6.54852262 1.89857294]] (4, 5)\n",
"[ 0. 2.43801551 1.14698713 103.61003706 1.03785953\n",
" 0. 8.18542165 1.04722073 6.29720982 1.31467809\n",
" 0. 1.36313403 4.04802126 1.57847092 2.76690688\n",
" 0. 2.07155059 1.03847754 6.54852262 1.89857294] (20,)\n"
]
}
],
......@@ -849,7 +849,7 @@
},
{
"cell_type": "code",
"execution_count": 82,
"execution_count": 34,
"metadata": {},
"outputs": [
{
......@@ -892,32 +892,39 @@
"source": [
"### Specialized numpy sub-packages:\n",
"\n",
"We already saw `numpy.random` to generate `numpy` arrays filled with random values. This submodule also provides functions related to distributions (Poisson, gaussian, etc.) and permutations."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To perform linear algebra with dense matrices, we can use the submodule `numpy.linalg`. For instance, in order to compute the determinant of a random matrix, we use the method `det`"
]
},
{
"cell_type": "code",
"execution_count": 83,
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.7389817 0.71953295 0.52116066 0.28674153 0.98808241]\n",
" [0.75973256 0.82099706 0.44055507 0.70815103 0.15250382]\n",
" [0.01277246 0.45752824 0.32131109 0.2052085 0.50415616]\n",
" [0.62710664 0.2525335 0.55259395 0.50973586 0.9498232 ]\n",
" [0.7880896 0.28579137 0.26261422 0.91569611 0.56513936]]\n"
"[[0.05786836 0.74775631 0.42819561 0.15943423 0.07020111]\n",
" [0.25120614 0.7005849 0.14757348 0.24445172 0.80359783]\n",
" [0.72029173 0.08179707 0.59376034 0.55689625 0.05431295]\n",
" [0.13524603 0.52603894 0.96931651 0.8754775 0.49138608]\n",
" [0.67129798 0.95741831 0.13709888 0.22486805 0.33238749]]\n"
]
},
{
"data": {
"text/plain": [
"0.06654501241365778"
"0.07677803052374542"
]
},
"execution_count": 83,
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
......@@ -932,12 +939,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy array can also be sorted, even when they are composed of complex data."
"`numpy` arrays can also be sorted, even when they are composed of complex data."
]
},
{
"cell_type": "code",
"execution_count": 84,
"execution_count": 36,
"metadata": {},
"outputs": [
{
......@@ -980,7 +987,7 @@
},
{
"cell_type": "code",
"execution_count": 85,
"execution_count": 37,
"metadata": {},
"outputs": [
{
......@@ -1004,7 +1011,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Note : `scipy` also provides a submodule for linear algebra `scipy.linalg`. It provides more features than `numpy.linalg` but it is equivalent (some functions are even in common). \n",
"Note : `scipy` also provides a submodule for linear algebra `scipy.linalg`. It provides an extension of `numpy.linalg`.\n",
"\n",
"For more info, see the related FAQ entry: https://www.scipy.org/scipylib/faq.html#why-both-numpy-linalg-and-scipy-linalg-what-s-the-difference."
]
......@@ -1039,7 +1046,7 @@
},
{
"cell_type": "code",
"execution_count": 86,
"execution_count": 38,
"metadata": {},
"outputs": [
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment