{"id":88582,"date":"2023-11-30T18:00:06","date_gmt":"2023-11-30T12:30:06","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=88582"},"modified":"2023-11-30T18:00:06","modified_gmt":"2023-11-30T12:30:06","slug":"numpy-statistical-functions","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/","title":{"rendered":"Numpy Statistical Functions with Examples"},"content":{"rendered":"<h2>Stats under our Hats!<\/h2>\n<p><strong>A Beginner-Friendly Tutorial on Numpy Statistical Functions<\/strong><\/p>\n<p>Welcome to Techvidvan&#8217;s beginner-friendly tutorial on Numpy statistical functions! Numpy is a powerful library in Python that is widely used for numerical computations and data analysis. In this tutorial, we&#8217;ll dive into some essential statistical functions offered by Numpy, along with examples to help you understand how to use them effectively.<\/p>\n<h3>Importing Numpy<\/h3>\n<p>To use Numpy in your Python code, you need to import it. Conventionally, Numpy is imported as np.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np<\/pre>\n<h3>Calculating Mean and Median<\/h3>\n<h4>Mean<\/h4>\n<p>The mean is the average value of a set of numbers. Numpy&#8217;s np.mean() function calculates the arithmetic mean.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nmean_value = np.mean(data)\nprint(\"Mean:\", mean_value)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Mean:<\/strong> 21.25<\/p>\n<h4>Median<\/h4>\n<p>The median is the middle value of a dataset when it&#8217;s arranged in ascending order. Numpy&#8217;s np.median() function calculates the median.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nmedian_value = np.median(data)\nprint(\"Median:\", median_value)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Median:<\/strong> 21.0<\/p>\n<h3>Calculating Standard Deviation and Variance<\/h3>\n<h4>Standard Deviation<\/h4>\n<p>The standard deviation is used to measure the dispersion of data points around the mean. Numpy&#8217;s np.std() function calculates the standard deviation of the data provided.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nstd_deviation = np.std(data)\nprint(\"Standard Deviation:\", std_deviation)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Standard Deviation:<\/strong> 5.681907957381501<\/p>\n<h4>Variance<\/h4>\n<p>Variance quantifies the spread between numbers in a dataset. Numpy&#8217;s np.var() function calculates the variance.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nvariance = np.var(data)\nprint(\"Variance:\", variance)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Variance:<\/strong> 32.25<\/p>\n<h3>Finding Maximum and Minimum Values<\/h3>\n<h4>Maximum<\/h4>\n<p>To find the maximum value in a dataset, Numpy provides the np.max() function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nmax_value = np.max(data)\nprint(\"Maximum Value:\", max_value)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Maximum Value:<\/strong> 30<\/p>\n<h4>Minimum<\/h4>\n<p>Similarly, to find the minimum value, you can use the np.min() function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nmin_value = np.min(data)\nprint(\"Minimum Value:\", min_value)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Minimum Value:<\/strong> 12<\/p>\n<h3>Calculating Correlation Coefficient<\/h3>\n<p>The correlation coefficient determines the strength and direction of a linear relationship between two variables. Numpy&#8217;s np.corrcoef() function computes the correlation matrix of the data given.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data_x = np.array([15, 18, 20, 22, 25, 30, 28, 35])\ndata_y = np.array([50, 55, 60, 65, 70, 75, 80, 85])\ncorrelation_matrix = np.corrcoef(data_x, data_y)\ncorrelation_coefficient = correlation_matrix[0, 1]\nprint(\"Correlation Coefficient:\", correlation_coefficient)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Correlation Coefficient:<\/strong> 0.9938079899999066<\/p>\n<h3>Additional Statistical Functions<\/h3>\n<h4>Percentiles<\/h4>\n<p>Percentiles help you understand the distribution of data. Numpy&#8217;s np.percentile() function calculates the value below which a given percentage of observations fall.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\npercentile_75 = np.percentile(data, 75)\nprint(\"75th Percentile:\", percentile_75)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>75th Percentile:<\/strong> 27.5<\/p>\n<h4>Histogram<\/h4>\n<p>Creating histograms is essential for visualizing data distribution. Numpy&#8217;s np.histogram() function computes the frequency of values within specified bins.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data = np.array([12, 18, 22, 15, 20, 25, 30, 28])\nhist, bins = np.histogram(data, bins=3)\nprint(\"Histogram:\", hist)\nprint(\"Bin Edges:\", bins)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Histogram:<\/strong> [3 3 2]<br \/>\n<strong>Bin Edges:<\/strong> [12. 16. 20. 24. 28. 32. 36.]<\/p>\n<h4>Covariance<\/h4>\n<p>Covariance measures the relationship between two sets of data. Numpy&#8217;s np.cov() function calculates the covariance matrix.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">data_x = np.array([15, 18, 20, 22, 25, 30, 28, 35])\ndata_y = np.array([50, 55, 60, 65, 70, 75, 80, 85])\ncovariance_matrix = np.cov(data_x, data_y)\ncovariance = covariance_matrix[0, 1]\nprint(\"Covariance:\", covariance)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong>Covariance:<\/strong> 62.57142857142857<\/p>\n<h3>Conclusion<\/h3>\n<p>Congratulations! You&#8217;ve learned some fundamental Numpy statistical functions through this Techvidvan tutorial. These functions are incredibly useful for analyzing and understanding your data. Feel free to experiment with different datasets and explore more advanced statistical functions that Numpy offers. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stats under our Hats! A Beginner-Friendly Tutorial on Numpy Statistical Functions Welcome to Techvidvan&#8217;s beginner-friendly tutorial on Numpy statistical functions! Numpy is a powerful library in Python that is widely used for numerical computations&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":88962,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[385],"tags":[5247,5253,5254,384,5255,5256],"class_list":["post-88582","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy-tutorials","tag-numpy","tag-numpy-statistical-functions","tag-numpy-statistical-functions-with-examples","tag-numpy-tutorial","tag-statistical-function-in-numpy","tag-statistical-functions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Numpy Statistical Functions with Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Some essential statistical functions are offered by Numpy, along with examples to help you understand how to use them effectively.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Numpy Statistical Functions with Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Some essential statistical functions are offered by Numpy, along with examples to help you understand how to use them effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-30T12:30:06+00:00\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Numpy Statistical Functions with Examples - TechVidvan","description":"Some essential statistical functions are offered by Numpy, along with examples to help you understand how to use them effectively.","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:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/","og_locale":"en_US","og_type":"article","og_title":"Numpy Statistical Functions with Examples - TechVidvan","og_description":"Some essential statistical functions are offered by Numpy, along with examples to help you understand how to use them effectively.","og_url":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-11-30T12:30:06+00:00","author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Numpy Statistical Functions with Examples","datePublished":"2023-11-30T12:30:06+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/"},"wordCount":396,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#primaryimage"},"thumbnailUrl":"","keywords":["numpy","numpy statistical functions","numpy statistical functions with examples","numPy tutorial","statistical function in numpy","statistical functions"],"articleSection":["NumPy Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/","url":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/","name":"Numpy Statistical Functions with Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#primaryimage"},"thumbnailUrl":"","datePublished":"2023-11-30T12:30:06+00:00","description":"Some essential statistical functions are offered by Numpy, along with examples to help you understand how to use them effectively.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/numpy-statistical-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Numpy Statistical Functions with Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=88582"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/88582\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=88582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=88582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=88582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}