{"id":3406,"date":"2021-12-11T07:50:31","date_gmt":"2021-12-11T07:50:31","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=3406"},"modified":"2022-08-16T02:02:35","modified_gmt":"2022-08-16T02:02:35","slug":"python-numpy","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/python-numpy\/","title":{"rendered":"Python NumPy"},"content":{"rendered":"\n<p>This Python NumPy Tutorial helps you learn NumPy from scratch so that you can use it effectively in your data science &amp; machine learning projects.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2022\/08\/numpy-tutorial.svg\" alt=\"numpy tutorial\" class=\"wp-image-4295\" width=\"200\" height=\"213\" title=\"numpy tutorial\"\/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id='what-youll-learn'>What you&#8217;ll learn <a href=\"#what-youll-learn\" class=\"anchor\" id=\"what-youll-learn\" title=\"Anchor for What you&#039;ll learn\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Create single and multi-dimensional NumPy arrays<\/li><li>Effectively use NumPy built-in functions &amp; methods<\/li><li>Perform mathematical operations on arrays<\/li><li>Extract elements from arrays using slicing and indexing<\/li><li>Select elements of arrays conditionally.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='getting-started'>Section 1. Getting started <a href=\"#getting-started\" class=\"anchor\" id=\"getting-started\" title=\"Anchor for Section 1. Getting started\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/what-is-numpy\/\">What is NumPy<\/a> &#8211; learn what NumPy is and what it can do for you.<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='creating-arrays'>Section 2. Creating arrays <a href=\"#creating-arrays\" class=\"anchor\" id=\"creating-arrays\" title=\"Anchor for Section 2. Creating arrays\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/create-numpy-array\/\">Creating arrays<\/a> &#8211; show you how to create numpy arrays.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-zeros\/\">zeros()<\/a> &#8211; create a numpy array of a given shape whose elements are filled with zeros.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-ones\/\">ones()<\/a> &#8211; create a numpy array of a given shape whose elements are filled with ones.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-arange\/\">arange()<\/a> &#8211; &nbsp;create a numpy array with evenly spaced numbers.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-linspace\/\">linspace()<\/a> &#8211; create a new numpy array with evenly spaced numbers of a specified interval.<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='array-indexing-slicing'>Section 3. Array indexing &amp; slicing <a href=\"#array-indexing-slicing\" class=\"anchor\" id=\"array-indexing-slicing\" title=\"Anchor for Section 3. Array indexing &amp; slicing\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-array-indexing\/\">Indexing<\/a> &#8211; learn how to select elements using indexing.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-array-slicing\/\">Slicing<\/a> &#8211; show you how to use slices to extract elements from an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/fancy-indexing\/\">Fancy indexing<\/a> &#8211; learn how to index a numpy array using another numpy array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/boolean-indexing\/\">Boolean indexing<\/a> &#8211; guide you on how to index an array using another array of boolean values.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-copy\/\">View vs. copy<\/a> &#8211; show you the difference between a view &amp; copy of an array and how to use the copy() method to make a copy of an array.<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='aggregate-functions'>Section 4. Aggregate functions <a href=\"#aggregate-functions\" class=\"anchor\" id=\"aggregate-functions\" title=\"Anchor for Section 4. Aggregate functions\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-sum\/\">sum()<\/a>&#8211; return the sum of all elements<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-mean\/\">mean()<\/a> &#8211; return the average of all elements in an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-var\/\">var() <\/a>&#8211; return the variance of all elements in an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-std\/\">std()<\/a> &#8211; calculate the standard deviation of elements of an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-prod\/\">prod()<\/a> &#8211; return the product of all elements.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-amin\/\">amin()<\/a> &#8211; return the minimum value in an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-amax\/\">amax()<\/a> &#8211; return the maximum value in an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-all\/\">all()<\/a> &#8211;  return <code>True<\/code> if all elements in an array evaluate to <code>True<\/code>.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-any\/\">any()<\/a> &#8211; return True if any of the elements in an array is nonzero.<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='array-operations'>Section 5. Array operations <a href=\"#array-operations\" class=\"anchor\" id=\"array-operations\" title=\"Anchor for Section 5. Array operations\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-reshape\/\">reshape()<\/a> &#8211; give an array a new shape while keeping the same elements.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-transpose\/\">transpose()<\/a> &#8211; return a view of an array with axes transposed.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-sort\/\">sort()<\/a> &#8211; return a sorted copy of an array.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-flatten\/\">flatten()<\/a> &#8211; return a copy of an array collapsed into one dimension.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-ravel\/\">ravel()<\/a> &#8211; return a contiguous flattened array.<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='arithmetic-operations'>Section 6. Arithmetic operations <a href=\"#arithmetic-operations\" class=\"anchor\" id=\"arithmetic-operations\" title=\"Anchor for Section 6. Arithmetic operations\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-add\/\">add()<\/a> &#8211; return the sum of two equal-sized arrays.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-subtract\/\">subtract()<\/a> &#8211; return the difference between two equal-sized arrays.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-multiply\/\">multiply()<\/a> &#8211; return the product of two equal-sized arrays.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-divide\/\">divide()<\/a> &#8211; return the quotient of two equal-sized arrays.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-broadcasting\/\">Broadcasting<\/a> &#8211; show you how NumPy uses broadcasting to perform arithmetic operations on arrays with different shapes.<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h2 class=\"wp-block-heading\" id='joining-splitting-arrays'>Section 7. Joining &amp; splitting arrays <a href=\"#joining-splitting-arrays\" class=\"anchor\" id=\"joining-splitting-arrays\" title=\"Anchor for Section 7. Joining &amp; splitting arrays\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-concatenate\/\">concatenate()<\/a> &#8211; join two or more arrays along an existing axis.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-stack\/\">stack()<\/a> &#8211; join two or more arrays along a new axis.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-vstack\/\">vstack()<\/a> &#8211; join two or more arrays vertically.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-hstack\/\">hstack()<\/a> &#8211; join two or more arrays horizontally.<\/li><li><a href=\"https:\/\/www.pythontutorial.net\/python-numpy\/numpy-split\/\">split()<\/a> &#8211; split an array into subarrays.<\/li><\/ul>\n<\/div><\/div>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3406\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-numpy\/\"\n\t\t\t\tdata-post-title=\"Python NumPy\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3406\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-numpy\/\"\n\t\t\t\tdata-post-title=\"Python NumPy\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This Python NumPy Tutorial helps you learn NumPy from scratch so that you can use it effectively in your data science &#038; machine learning projects.<\/p>\n","protected":false},"author":1,"featured_media":4295,"parent":0,"menu_order":9,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3406","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=3406"}],"version-history":[{"count":0,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3406\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media\/4295"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=3406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}