{"id":136388,"date":"2024-09-23T14:02:49","date_gmt":"2024-09-23T08:32:49","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=136388"},"modified":"2024-09-23T14:02:50","modified_gmt":"2024-09-23T08:32:50","slug":"introduction-to-numpy-arrays","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/","title":{"rendered":"Introduction to NumPy Arrays"},"content":{"rendered":"\n<p><strong>NumPy<\/strong> is a fundamental library for scientific computing in Python, providing powerful tools for working with numerical data. At the core of NumPy is the <strong>ndarray<\/strong> object, a multidimensional array that is optimized for efficient numerical operations.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Understanding NumPy Arrays<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Homogeneous Data:<\/strong> Unlike Python lists, NumPy arrays are homogeneous, meaning all elements must be of the same data type (e.g., integers, floats, strings).<\/li>\n\n\n\n<li><strong>Multidimensional Structure:<\/strong> NumPy arrays can have any number of dimensions, from 1D vectors to higher-dimensional matrices.<\/li>\n\n\n\n<li><strong>Efficient Storage:<\/strong> NumPy arrays are stored in contiguous memory blocks, allowing for efficient operations and faster execution times compared to Python lists.<\/li>\n\n\n\n<li><strong>Broadcasting:<\/strong> NumPy&#8217;s broadcasting mechanism enables operations between arrays of different shapes, providing flexibility in calculations.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Creating NumPy Arrays<\/strong><\/h3>\n\n\n\n<p><strong>Direct Initialization:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<p>import numpy as np<\/p>\n\n\n\n<p># Create a 1D array<\/p>\n\n\n\n<p>arr1d = np.array([1, 2, 3])<\/p>\n\n\n\n<p># Create a 2D array<\/p>\n\n\n\n<p>arr2d = np.array([[1, 2], [3, 4]])<\/p>\n\n\n\n<p><strong>Using Array Creation Functions:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<p># Create an array of zeros<\/p>\n\n\n\n<p>zeros = np.zeros((2, 3))<\/p>\n\n\n\n<p># Create an array of ones<\/p>\n\n\n\n<p>ones = np.ones((3, 4))<\/p>\n\n\n\n<p># Create an array of random values<\/p>\n\n\n\n<p>random = np.random.rand(2, 2)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Accessing and Modifying Array Elements<\/strong><\/h3>\n\n\n\n<p><strong>Indexing:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<p># Access an element<\/p>\n\n\n\n<p>element = arr1d[0]\n\n\n\n<p># Access a slice<\/p>\n\n\n\n<p>slice = arr2d[1:3, 0:2]\n\n\n\n<p><strong>Boolean Indexing:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<p># Create a boolean mask<\/p>\n\n\n\n<p>mask = arr1d > 2<\/p>\n\n\n\n<p># Extract elements based on the mask<\/p>\n\n\n\n<p>result = arr1d[mask]\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Array Attributes<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Shape:<\/strong> The dimensions of the array (e.g., (2, 3) for a 2&#215;3 matrix).<\/li>\n\n\n\n<li><strong>dtype:<\/strong> The data type of the elements in the array (e.g., int32, float64).<\/li>\n\n\n\n<li><strong>ndim:<\/strong> The number of dimensions of the array.<\/li>\n\n\n\n<li><strong>size:<\/strong> The total number of elements in the array.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Basic Array Operations<\/strong><\/h3>\n\n\n\n<p><strong>Arithmetic Operations:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<p>result = arr1d + arr2d<br>result = arr1d * 2<\/p>\n\n\n\n<p><strong>Matrix Operations:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Matrix multiplication<\/h1>\n\n\n\n<p>result = np.dot(arr2d, arr2d.T)<\/p>\n\n\n\n<p><strong>Aggregation Functions:<\/strong><\/p>\n\n\n\n<p>Python<\/p>\n\n\n\n<p>sum = np.sum(arr1d)<br>mean = np.mean(arr2d)<\/p>\n\n\n\n<p>By understanding the fundamentals of NumPy arrays, you can effectively work with numerical data and perform various computations efficiently in Python.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NumPy is a fundamental library for scientific computing in Python, providing powerful tools for working with numerical data. At the core of NumPy is the ndarray object, a multidimensional array that is optimized for efficient numerical operations. Understanding NumPy Arrays Creating NumPy Arrays Direct Initialization: Python import numpy as np # Create a 1D array&#8230;<\/p>\n","protected":false},"author":16,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-136388","page","type-page","status-publish","hentry"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introduction to NumPy Arrays - Tutorial<\/title>\n<meta name=\"description\" content=\"Explore NumPy arrays, the foundation of numerical computing in Python, and learn how they streamline data manipulation and computation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to NumPy Arrays - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Explore NumPy arrays, the foundation of numerical computing in Python, and learn how they streamline data manipulation and computation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-23T08:32:50+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/\",\"name\":\"Introduction to NumPy Arrays - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2024-09-23T08:32:49+00:00\",\"dateModified\":\"2024-09-23T08:32:50+00:00\",\"description\":\"Explore NumPy arrays, the foundation of numerical computing in Python, and learn how they streamline data manipulation and computation.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to NumPy Arrays\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to NumPy Arrays - Tutorial","description":"Explore NumPy arrays, the foundation of numerical computing in Python, and learn how they streamline data manipulation and computation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to NumPy Arrays - Tutorial","og_description":"Explore NumPy arrays, the foundation of numerical computing in Python, and learn how they streamline data manipulation and computation.","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-09-23T08:32:50+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/","name":"Introduction to NumPy Arrays - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2024-09-23T08:32:49+00:00","dateModified":"2024-09-23T08:32:50+00:00","description":"Explore NumPy arrays, the foundation of numerical computing in Python, and learn how they streamline data manipulation and computation.","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/introduction-to-numpy-arrays\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Introduction to NumPy Arrays"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=136388"}],"version-history":[{"count":1,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136388\/revisions"}],"predecessor-version":[{"id":136395,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/136388\/revisions\/136395"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=136388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=136388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=136388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}