{"id":2276,"date":"2020-04-14T19:36:40","date_gmt":"2020-04-14T17:36:40","guid":{"rendered":"http:\/\/www.ardpylab.fr\/?page_id=2276"},"modified":"2020-05-10T16:24:10","modified_gmt":"2020-05-10T14:24:10","slug":"la-bibliotheque-numpy","status":"publish","type":"page","link":"https:\/\/www.ardpylab.fr\/?page_id=2276","title":{"rendered":"La biblioth\u00e8que numpy"},"content":{"rendered":"\n<p>&nbsp;<\/p>\n<p><strong>numPy<\/strong> (diminutif de numerical Python) est la biblioth\u00e8que indispensable pour le calcul scientifique avec Python.<\/p>\n<p>Cette biblioth\u00e8que est utile pour manipuler des matrices ou tableaux multidimensionnels ainsi que les fonctions math\u00e9matiques op\u00e9rant sur ces tableaux.<\/p>\n\n\n\n<h4><span style=\"text-decoration: underline; color: #0000ff;\"><strong><br>Les bases de l\u2019utilisation de numpy<\/strong><\/span><\/h4>\n<p>Il faut au d\u00e9part importer le package numpy avec l\u2019instruction recommand\u00e9e suivante :<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 60px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 60px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2277\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy1.png\" alt=\"\" width=\"223\" height=\"42\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Toutes les fonctions de <strong>NumPy<\/strong> seront alors pr\u00e9fix\u00e9es par <strong>np<\/strong>.<\/p>\n<p>Le package <strong>NumPy <\/strong>permet la manipulation simple et efficace des tableaux en ajoutant \u00e0 Python le type <strong>array<\/strong> similaire \u00e0 une liste (type <strong>list<\/strong>). Mais contrairement aux listes, les tableaux <strong>Numpy<\/strong> ne peuvent contenir que des membres d&rsquo;un seul type.<\/p>\n<p>Pour cr\u00e9er un tableau Numpy, on peut convertir une liste avec la fonction <strong>array()<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 63px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 63px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2278\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy2.png\" alt=\"\" width=\"319\" height=\"91\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Le deuxi\u00e8me argument est optionnel et sp\u00e9cifie le type des \u00e9l\u00e9ments du tableau&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2279\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy3.png\" alt=\"\" width=\"351\" height=\"56\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Si dans la liste de d\u00e9part, il y a des donn\u00e9es de types diff\u00e9rents, <strong>Numpy<\/strong> essaiera de les convertir toutes au type le plus g\u00e9n\u00e9ral. Par exemple, les entiers <strong>int<\/strong> seront convertis en nombres \u00e0 virgule flottante <strong>float<\/strong> :<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2280\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy4.png\" alt=\"\" width=\"317\" height=\"57\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Un tableau peut \u00eatre multidimensionnel ; ici 2 dimensions&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2281\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy5-300x58.png\" alt=\"\" width=\"362\" height=\"70\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy5-300x58.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy5.png 327w\" sizes=\"auto, (max-width: 362px) 100vw, 362px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Comme pour les listes, on peut acc\u00e9der aux \u00e9l\u00e9ments d\u2019un tableau (attention, comme pour les listes, les indices des \u00e9l\u00e9ments commencent \u00e0 z\u00e9ro)&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2282\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy6-300x115.png\" alt=\"\" width=\"350\" height=\"134\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy6-300x115.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy6.png 328w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Et le slicing (d\u00e9coupage) extrait les tableaux&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2283\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy7-300x118.png\" alt=\"\" width=\"550\" height=\"217\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy7-300x118.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy7.png 535w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Dans l\u2019instruction <strong>[d\u00e9but:fin:pas]<\/strong>, deux des arguments peuvent \u00eatre omis : par d\u00e9faut l\u2019indice de d\u00e9but vaut 0 (le 1er \u00e9l\u00e9ment du tableau), et le pas vaut 1.<\/p>\n<p>Un pas n\u00e9gatif inversera l\u2019ordre du tableau&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2284\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy8-300x64.png\" alt=\"\" width=\"328\" height=\"70\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy8-300x64.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy8.png 303w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Et avec un d\u00e9but n\u00e9gatif, la lecture commence par la fin&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2285\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy10.png\" alt=\"\" width=\"124\" height=\"40\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Pour un tableau bi-dimensionnel, on peut bien-s\u00fbr travailler avec les deux indices&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2286\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy11-300x78.png\" alt=\"\" width=\"331\" height=\"86\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy11-300x78.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy11.png 325w\" sizes=\"auto, (max-width: 331px) 100vw, 331px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Et on peut modifier les valeurs d\u2019un tableau&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2287\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy12-300x117.png\" alt=\"\" width=\"353\" height=\"138\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy12-300x117.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy12.png 328w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><br>En fait, un tableau multidimensionnel est repr\u00e9sent\u00e9 par une liste de listes, et au final, un tableau bi-dimensionnel (lignes et colonnes) n&rsquo;est rien d&rsquo;autre qu&rsquo;une liste de lignes, une ligne \u00e9tant une liste de nombres.<\/p>\n<p>On peut alors facilement cr\u00e9er un tableau bi-dimensionnel avec la fonction <strong>range()<\/strong>&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2299\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy9-300x47.png\" alt=\"\" width=\"415\" height=\"65\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy9-300x47.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy9.png 429w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Ce qui donne&nbsp;le tableau suivant :<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"838\" height=\"151\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/image.png\" alt=\"\" class=\"wp-image-2300\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/image.png 838w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/image-300x54.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/image-768x138.png 768w\" sizes=\"auto, (max-width: 838px) 100vw, 838px\" \/><\/figure><\/div>\n\n\n\n<p>Avec&nbsp;:<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2301\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy13-300x133.png\" alt=\"\" width=\"415\" height=\"184\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy13-300x133.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy13.png 432w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><br>Cependant, <strong>Numpy<\/strong> dispose de plusieurs fonctions pour cr\u00e9er directement des tableaux :<\/p>\n<p><strong>. Zeros()<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px; width: 100%;\">\n<p># Un tableau bi-dimensionnel de taille 1&#215;10, rempli d&rsquo;entiers qui valent 0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2303\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy14-300x31.png\" alt=\"\" width=\"329\" height=\"34\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy14-300x31.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy14.png 302w\" sizes=\"auto, (max-width: 329px) 100vw, 329px\" \/><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><strong>. Ones()<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\">\n<p># Un tableau bi-dimensionnel de taille 3&#215;5, rempli de nombres \u00e0 virgule flottante de valeur 1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2304\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy15.png\" alt=\"\" width=\"236\" height=\"65\"><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><strong>. full()<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\">\n<p># Un tableau bi-dimensionnel de taille 3&#215;5, rempli de 2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2305\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy16.png\" alt=\"\" width=\"199\" height=\"66\"><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><strong>. arange()<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\">\n<p># Un tableau bi-dimensionnel de taille 1&#215;10, rempli d\u2019une s\u00e9quence lin\u00e9aire d&rsquo;entiers<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2306\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy17.png\" alt=\"\" width=\"299\" height=\"34\"><\/p>\n<p># Un tableau rempli d\u2019une s\u00e9quence lin\u00e9aire de nombres \u00e0 virgule flottante<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2307\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy18-300x67.png\" alt=\"\" width=\"318\" height=\"71\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy18-300x67.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy18.png 314w\" sizes=\"auto, (max-width: 318px) 100vw, 318px\" \/><\/p>\n<p># Un tableau rempli d\u2019une s\u00e9quence lin\u00e9aire d\u2019entiers par pas de 2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2309\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy19-300x28.png\" alt=\"\" width=\"385\" height=\"36\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy19-300x28.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy19.png 382w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/p>\n<p># Un tableau rempli d\u2019une s\u00e9quence lin\u00e9aire de nombres \u00e0 virgule flottante par pas de 0.1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2310\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy20-300x23.png\" alt=\"\" width=\"482\" height=\"37\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy20-300x23.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy20.png 462w\" sizes=\"auto, (max-width: 482px) 100vw, 482px\" \/><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><u>Remarque<\/u>&nbsp;:<\/p>\n<p>Dans l\u2019instruction np.arange<strong>(d\u00e9but:fin:pas)<\/strong>, deux des arguments peuvent \u00eatre omis :<\/p>\n<p style=\"padding-left: 40px;\">. <strong>d\u00e9but<\/strong>&nbsp;: par d\u00e9faut l\u2019indice de d\u00e9but vaut 0 (le 1er \u00e9l\u00e9ment du tableau)<\/p>\n<p style=\"padding-left: 40px;\">. <strong>pas<\/strong>&nbsp;: par d\u00e9faut le pas vaut 1.<\/p>\n<p>Le dernier \u00e9l\u00e9ment du tableau est l\u2019argument <strong>fin<\/strong> auquel il faut retrancher le <strong>pas.<br><br><\/strong><\/p>\n<p><strong>. linspace()<\/strong><\/p>\n<p>Comme il y quelques subtilit\u00e9s avec la fonction <strong>arange()<\/strong> quant au dernier \u00e9l\u00e9ment, pour \u00e9viter tout probl\u00e8me, la fonction <strong>linspace(premier,dernier,n)<\/strong> renvoie un array commen\u00e7ant par <strong>premier<\/strong>, se terminant par <strong>dernier<\/strong> avec <strong>n<\/strong> \u00e9l\u00e9ments.<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2311\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy21.png\" alt=\"\" width=\"326\" height=\"36\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p><strong>. reshape ()<\/strong><\/p>\n<p>La fonction reshape() permet de redimensionner un tableau. Il faut cependant que le nombre d\u2019\u00e9l\u00e9ments reste le m\u00eame.<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2314\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy22-300x110.png\" alt=\"\" width=\"540\" height=\"198\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy22-300x110.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy22.png 570w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>NumPy dispose d\u2019un grand nombre de fonctions math\u00e9matiques qui peuvent \u00eatre appliqu\u00e9es directement \u00e0 un tableau. Dans ce cas, la fonction est appliqu\u00e9e \u00e0 chacun des \u00e9l\u00e9ments du tableau.<\/p>\n\n\n\n<figure class=\"wp-block-table\">\n<table style=\"width: 100%; height: 70px;\">\n<tbody>\n<tr style=\"height: 70px;\">\n<td style=\"height: 70px; padding-left: 40px;\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2315\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy23-300x79.png\" alt=\"\" width=\"369\" height=\"97\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy23-300x79.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy23.png 381w\" sizes=\"auto, (max-width: 369px) 100vw, 369px\" \/><br><br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-2316\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy24-300x76.png\" alt=\"\" width=\"367\" height=\"93\" srcset=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy24-300x76.png 300w, https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/04\/pythonnumpy24.png 377w\" sizes=\"auto, (max-width: 367px) 100vw, 367px\" \/><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n\n<p>Les fonctions math\u00e9matiques couramment utilis\u00e9es sont&nbsp;:<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.sin(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sinus<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.cos(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cosinus<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.tan(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tangente<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.arcsin(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arcsinus<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.arccos(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arccosinus<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.arctan(x)<\/strong>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arctangente<\/p>\n<p style=\"padding-left: 40px;\">. <strong>x**n<\/strong>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x \u00e0 la puissance n, exemple : x**2<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.sqrt(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; racine carr\u00e9e<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.exp(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exponentielle<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.log(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logarithme n\u00e9p\u00e9rien<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.abs(x)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valeur absolue<\/p>\n<p style=\"padding-left: 40px;\">. <strong>numpy.around(x,n)<\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arrondi \u00e0 n d\u00e9cimales<\/p>\n\n\n\n<p><br \/>On va donc pouvoir appliquer n\u2019importe quelle fonction math\u00e9matique \u00e0 un tableau de donn\u00e9es <strong>x<\/strong> de fa\u00e7on \u00e0 obtenir la caract\u00e9ristique <strong>y=f(x)<\/strong>.<\/p>\n<p>Cette caract\u00e9ristique pourra \u00eatre trac\u00e9 \u00e0 l\u2019aide de la biblioth\u00e8que <strong>matplolib<\/strong>.<\/p>\n<p>\u00a0<\/p>\n\n\n<div  class=\"grids-section grids-is-stretch\" style=\"--_gs-gap-desktop:0px 0px;--_gs-m-desktop:0 0 0 0;--_gs-p-desktop:0 0 0 0;--_gs-bg-desktop:transparent none;--_gs-bg-xp-desktop:0px;--_gs-zi-desktop:auto;--_gs-d-desktop:block;--_gs-mw-desktop:calc(100% - 0 - 0);--_gs-gap-tablet:0px 0px;--_gs-m-tablet:0 0 0 0;--_gs-p-tablet:0 0 0 0;--_gs-bg-tablet:transparent none;--_gs-bg-xp-tablet:0px;--_gs-zi-tablet:auto;--_gs-d-tablet:block;--_gs-mw-tablet:calc(100% - 0 - 0);--_gs-gap-mobile:0px 0px;--_gs-m-mobile:0 0 0 0;--_gs-p-mobile:0 0 0 0;--_gs-bg-mobile:transparent none;--_gs-bg-xp-mobile:0px;--_gs-zi-mobile:auto;--_gs-d-mobile:block;--_gs-mw-mobile:calc(100% - 0 - 0);--_gs-columns:2;--_gs-rows:1\"><div class=\"grids-s-w_i\">\n<div class=\"grids-area\" style=\"--_ga-column:1\/2;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=2201\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/moins.jpg\" alt=\"\" class=\"wp-image-107\"\/><\/a><\/figure><\/div>\n\n<\/div>\n\n<div class=\"grids-area\" style=\"--_ga-column:2\/3;--_ga-row:1\/2;--_ga-m-desktop:0 0 0 0;--_ga-p-desktop:0 0 0 0;--_ga-bg-desktop:transparent none;--_ga-zi-desktop:auto;--_ga-d-desktop:flex;--_ga-mw-desktop:calc(100% - 0 - 0);--_ga-m-tablet:0 0 0 0;--_ga-p-tablet:0 0 0 0;--_ga-bg-tablet:transparent none;--_ga-zi-tablet:auto;--_ga-d-tablet:flex;--_ga-mw-tablet:calc(100% - 0 - 0);--_ga-m-mobile:0 0 0 0;--_ga-p-mobile:0 0 0 0;--_ga-bg-mobile:transparent none;--_ga-zi-mobile:auto;--_ga-d-mobile:flex;--_ga-mw-mobile:calc(100% - 0 - 0)\">\n\n<div class=\"wp-block-image\"><figure class=\"alignright size-large\"><a href=\"https:\/\/www.ardpylab.fr\/?page_id=2324\"><img loading=\"lazy\" decoding=\"async\" width=\"50\" height=\"28\" src=\"https:\/\/www.ardpylab.fr\/wp-content\/uploads\/2020\/03\/plus.jpg\" alt=\"\" class=\"wp-image-106\"\/><\/a><\/figure><\/div>\n\n<\/div>\n<\/div><\/div>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; numPy (diminutif de numerical Python) est la biblioth\u00e8que indispensable pour le calcul scientifique avec Python. Cette biblioth\u00e8que est utile pour manipuler des matrices ou tableaux multidimensionnels ainsi que les fonctions math\u00e9matiques op\u00e9rant sur ces tableaux. Les bases de l\u2019utilisation de numpy Il faut au d\u00e9part importer le package numpy avec l\u2019instruction recommand\u00e9e suivante : [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2276","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/2276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2276"}],"version-history":[{"count":0,"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=\/wp\/v2\/pages\/2276\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ardpylab.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}