{"id":22293,"date":"2020-11-13T18:59:51","date_gmt":"2020-11-13T13:29:51","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/"},"modified":"2024-04-30T18:44:55","modified_gmt":"2024-04-30T13:14:55","slug":"scipy-tutorial","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/","title":{"rendered":"SciPy Tutorial for Beginners"},"content":{"rendered":"\n<p>In this tutorial, we are going to start from scratch and see how to use SciPy, <a href=\"\/academy\/learn-for-free\/courses\/scipy-in-python\" target=\"_blank\" rel=\"noreferrer noopener\">scipy in python<\/a> and introduce you to some of its most important features. Also, we are going to go through the different modules or sub-packages present in the SciPy package and see how they are used.<br><\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-scipy\"><strong>What is SciPy?<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/scipy\/free-courses\" target=\"_blank\" rel=\"noreferrer noopener\">SciPy<\/a> is a free and open-source <a aria-label=\"Python (opens in a new tab)\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-tutorial-for-beginners-a-complete-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a> library used for scientific computing and technical computing. It is a collection of mathematical algorithms and convenience functions built on the NumPy extension of Python. It adds significant power to the interactive Python session by providing the user with high-level commands and classes for manipulating and visualizing data. As mentioned earlier, SciPy builds on NumPy and therefore if you import SciPy, there is no need to import <a aria-label=\"NumPy (opens in a new tab)\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-numpy-tutorial\/\" target=\"_blank\" rel=\"noreferrer noopener\">NumPy<\/a>.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"installing-scipy\"><strong>Installing SciPy<\/strong><\/h2>\n\n\n\n<p>Before learning more about the core functionality of SciPy, it should be installed in the system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-on-windows-and-linux\"><strong>Install on Windows and Linux<\/strong><\/h3>\n\n\n\n<p>Here are a few methods that can be used to install SciPy on Windows or Linux.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-scipy-using-pip\">Install SciPy using pip<\/h3>\n\n\n\n<p>We can install the SciPy library by using the pip command. Pip is basically a recursive acronym which stands for \u2018Pip Installs Packages\u2019. It is a standard package manager which can be installed in most of the operating systems. To install, run the following command in the terminal:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install scipy <strong>&nbsp;<\/strong><\/pre>\n\n\n\n<p><strong>Note: Use pip to install SciPy in Linux.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-scipy-using-anaconda\">Install SciPy using Anaconda<\/h3>\n\n\n\n<p>We can also install SciPy packages by using Anaconda. First, we need to download the Anaconda navigator and then open the anaconda prompt type the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">conda install -c anaconda scipy&nbsp;&nbsp;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-on-mac\"><strong>Install on Mac<\/strong><\/h3>\n\n\n\n<p>The mac doesn't have the preinstall package manager, but you can install various popular package managers. Run the following commands in the terminal it will download the SciPy as well as matplotlib, pandas, NumPy.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo port install py35-numpy py35-scipy py35-matplotlib py35-ipython +notebook py35-pandas py35-sympy py35-nose&nbsp;&nbsp;<br><\/pre>\n\n\n\n<p>Also, you can use Homebrew to install these packages. But keep in mind that it has incomplete coverage of the SciPy ecosystem:<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">brew install numpy scipy ipython jupyter<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sub-packages-in-scipy\"><strong>Sub packages in SciPy<\/strong><\/h2>\n\n\n\n<p>Many dedicated software tools are necessary for Python scientific computing, and SciPy is one such tool or library offering many Python modules that we can work with in order to perform complex operations.<\/p>\n\n\n\n<p>The following table shows some of the modules or sub-packages that can be used for computing:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Sr.<\/strong><\/td><td><strong>Sub-Package<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td><strong>1.<\/strong><\/td><td>scipy.cluster<\/td><td>Cluster algorithms are used to vector quantization\/ Kmeans.<\/td><\/tr><tr><td><strong>2.<\/strong><\/td><td>scipy.constants<\/td><td>It represents physical and mathematical constants.<\/td><\/tr><tr><td><strong>3.<\/strong><\/td><td>scipy.fftpack<\/td><td>It is used for Fourier transform.<\/td><\/tr><tr><td><strong>4.<\/strong><\/td><td>scipy.integrate<\/td><td>Integration routines<\/td><\/tr><tr><td><strong>5.<\/strong><\/td><td>scipy.interpolation<\/td><td>Interpolation<\/td><\/tr><tr><td><strong>6.<\/strong><\/td><td>scipy.linalg<\/td><td>It is used for linear algebra routine.<\/td><\/tr><tr><td><strong>7.<\/strong><\/td><td>scipy.io<\/td><td>It is used for data input and output.<\/td><\/tr><tr><td><strong>8.<\/strong><\/td><td>scipy.ndimage<\/td><td>It is used for the n-dimension image.<\/td><\/tr><tr><td><strong>9.<\/strong><\/td><td>scipy.odr<\/td><td>Orthogonal distance regression.<\/td><\/tr><tr><td><strong>10.<\/strong><\/td><td>scipy.optimize<\/td><td>It is used for optimization.<\/td><\/tr><tr><td><strong>11.<\/strong><\/td><td>scipy.signal<\/td><td>It is used in signal processing.<\/td><\/tr><tr><td><strong>12.<\/strong><\/td><td>scipy.sparse<\/td><td>Sparse matrices and associated routines.<\/td><\/tr><tr><td><strong>13.<\/strong><\/td><td>scipy.spatial<\/td><td>Spatial data structures and algorithms.<\/td><\/tr><tr><td><strong>14.<\/strong><\/td><td>scipy.special<\/td><td>Special Function.<\/td><\/tr><tr><td><strong>15.<\/strong><\/td><td>scipy.stats<\/td><td>Statistics.<\/td><\/tr><tr><td><strong>16.<\/strong><\/td><td>scipy.weaves<\/td><td>It is a tool for writing.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-cluster\"><strong>SciPy Cluster<\/strong><\/h2>\n\n\n\n<p>Clustering is the task of dividing the population or data points into a number of groups such that data points in the same groups are more similar to other data points in the same group and dissimilar to the data points in other groups. Each group which is formed from clustering is known as a cluster. There are two types of the cluster, which are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Central<\/li>\n\n\n\n<li>Hierarchy<\/li>\n<\/ul>\n\n\n\n<p>Here we will see how to implement the K-means clustering algorithm which is one of the popular clustering algorithms. The k-means algorithm adjusts the classification of the observations into clusters and updates the cluster centroids until the position of the centroids is stable over successive iterations.<\/p>\n\n\n\n<p>In the below implementation, we have used NumPy to generate two sets of random points. After joining both these sets, we whiten the data. Whitening normalizes the data and is an essential step before using k-means clustering. Finally, we use the kmeans functions and pass it the data and number of clustered we want.<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\nfrom scipy.cluster.vq import  kmeans, whiten\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nsns.set_style(&quot;darkgrid&quot;)\n# Create 50 datapoints in two clusters a and b\npts = 100\na = np.random.multivariate_normal(&#x5B;0, 0], \n                                  &#x5B;&#x5B;4, 1], &#x5B;1, 4]], \n                                  size=pts)\nb = np.random.multivariate_normal(&#x5B;30, 10],\n                                  &#x5B;&#x5B;10, 2], &#x5B;2, 1]],\n                                  size=pts)\nfeatures = np.concatenate((a, b))\n# Whiten data\nwhitened = whiten(features)\n# Find 2 clusters in the data\ncodebook, distortion = kmeans(whitened, 2)\n# Plot whitened data and cluster centers in red\nplt.scatter(whitened&#x5B;:, 0], whitened&#x5B;:, 1])\nplt.scatter(codebook&#x5B;:, 0], codebook&#x5B;:, 1], c=&#039;r&#039;)\nplt.show()\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0.png\"><img decoding=\"async\" width=\"380\" height=\"248\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0.png\" alt=\"scipy tutorial\" class=\"wp-image-22294\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0.png 380w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-300x196.png 300w\" sizes=\"(max-width: 380px) 100vw, 380px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-constants\"><strong>SciPy constants<\/strong><\/h2>\n\n\n\n<p>There are a variety of constants that are included in the scipy.constant sub-package.These constants are used in the general scientific area. Let us see how these constant variables are imported and used.<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#Import golden constant from the scipy   \nimport scipy\nprint(&quot;sciPy -golden ratio  Value = %.18f&quot;%scipy.constants.golden)\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">Output: \nsciPy -golden ratio&nbsp; Value = 1.618033988749894903 <\/pre>\n\n\n\n<p>As you can see, we imported and printed the golden ratio constant using SciPy.The scipy.constant also provides the find() function, which returns a list of physical_constant keys containing a given string.<\/p>\n\n\n\n<p>Consider the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom scipy.constants import find  \nfind(&#039;boltzmann&#039;)\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n['Boltzmann constant',\n&nbsp;'Boltzmann constant in Hz\/K',\n&nbsp;'Boltzmann constant in eV\/K',\n&nbsp;'Boltzmann constant in inverse meter per kelvin',\n&nbsp;'Stefan-Boltzmann constant']<\/pre>\n\n\n\n<p>Here is how you can get the value of the required constant:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nscipy.constants.physical_constants&#x5B;&#039;Boltzmann constant in Hz\/K&#039;]\n\n<\/pre><\/div>\n\n\n<p>Now let us see the list of constants that are included in this subpackage. The scipy.constant provides the following list of mathematical constants.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Sr. No.<\/strong><\/td><td><strong>Constants<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>1.<\/td><td>pi<\/td><td>pi<\/td><\/tr><tr><td>2.<\/td><td>golden<\/td><td>Golden ratio<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The scipy.constant.physical_sconstants provides the following list of physical constants.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Sr. No.<\/strong><\/td><td><strong>Physical Constants<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>1.<\/td><td>c<\/td><td>Speed of light in vacuum<\/td><\/tr><tr><td>2.<\/td><td>speed_of_light<\/td><td>Speed of light in vacuum<\/td><\/tr><tr><td>3.<\/td><td>G<\/td><td>Standard acceleration of gravity<\/td><\/tr><tr><td>4.<\/td><td>G<\/td><td>Newton Constant of gravitation<\/td><\/tr><tr><td>5.<\/td><td>E<\/td><td>Elementary charge<\/td><\/tr><tr><td>6.<\/td><td>R<\/td><td>Molar gas constant<\/td><\/tr><tr><td>7.<\/td><td>Alpha<\/td><td>Fine-structure constant<\/td><\/tr><tr><td>8.<\/td><td>N_A<\/td><td>Avogadro constant<\/td><\/tr><tr><td>9.<\/td><td>K<\/td><td>Boltzmann constant<\/td><\/tr><tr><td>10<\/td><td>Sigma<\/td><td>Stefan-Boltzmann constant \u03c3<\/td><\/tr><tr><td>11.<\/td><td>m_e<\/td><td>Electron mass<\/td><\/tr><tr><td>12.<\/td><td>m_p<\/td><td>Proton mass<\/td><\/tr><tr><td>13.<\/td><td>m_n<\/td><td>Neutron Mass<\/td><\/tr><tr><td>14.<\/td><td>H<\/td><td>Plank Constant<\/td><\/tr><tr><td>15.<\/td><td>Plank constant<\/td><td>Plank constant h<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/constants.html\">Here<\/a> is a complete list of constants that are included in the constant subpackage.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-fftpack\"><strong>SciPy FFTpack<\/strong><\/h2>\n\n\n\n<p>The FFT stands for Fast Fourier Transformation which is an algorithm for computing DFT. DFT is a mathematical technique which is used in converting spatial data into frequency data.<\/p>\n\n\n\n<p>SciPy provides the fftpack module, which is used to calculate Fourier transformation. In the example below, we will plot a simple periodic function of sin and see how the scipy.fft function will transform it.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom matplotlib import pyplot as plt\nimport numpy as np \nimport seaborn as sns\nsns.set_style(&quot;darkgrid&quot;)\n#Frequency in terms of Hertz\nfre  = 10\n#Sample rate\nfre_samp = 100\nt = np.linspace(0, 2, 2 * fre_samp, endpoint = False )\na = np.sin(fre  * 2 * np.pi * t)\nplt.plot(t, a)\nplt.xlabel(&#039;Time (s)&#039;)\nplt.ylabel(&#039;Signal amplitude&#039;)\nplt.show()\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-1.png\"><img decoding=\"async\" width=\"400\" height=\"262\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-1.png\" alt=\"scipy tutorial\" class=\"wp-image-22296\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-1.png 400w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-1-300x197.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom scipy import fftpack\nA = fftpack.fft(a)\nfrequency = fftpack.fftfreq(len(a)) * fre_samp\nplt.stem(frequency, np.abs(A),use_line_collection=True)\nplt.xlabel(&#039;Frequency in Hz&#039;)\nplt.ylabel(&#039;Frequency Spectrum Magnitude&#039;)\nplt.show()\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-2.png\"><img decoding=\"async\" width=\"389\" height=\"262\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-2.png\" alt=\"scipy tutorial\" class=\"wp-image-22298\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-2.png 389w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-2-300x202.png 300w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><\/figure>\n\n\n\n<p>This subpackage also provides us functions such as fftfreq() which will generate the sampling frequencies. Also fftpack.dct() function allows us to calculate the Discrete Cosine Transform (DCT).SciPy also provides the corresponding IDCT with the function idct().<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-integrate\"><strong>SciPy integrate<\/strong><\/h2>\n\n\n\n<p>The integrate sub package of the Scipy package contains a lot of functions that allow us to calculate the integral of some complex functions. If you use the help function, you will find all the different types of integrals you can calculate. Here is how:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; gutter: false; title: ; notranslate\" title=\"\">\nhelp(integrate)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">&nbsp;Methods for Integrating Functions given function object.\n\n&nbsp;&nbsp;&nbsp;quad&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- General purpose integration.\n&nbsp;&nbsp;&nbsp;dblquad &nbsp; &nbsp; &nbsp; -- General purpose double integration.\n&nbsp;&nbsp;&nbsp;tplquad &nbsp; &nbsp; &nbsp; -- General purpose triple integration.\n&nbsp;&nbsp;&nbsp;fixed_quad&nbsp; &nbsp; -- Integrate func(x) using Gaussian quadrature of order n.\n&nbsp;&nbsp;&nbsp;quadrature&nbsp; &nbsp; -- Integrate with given tolerance using Gaussian quadrature.\n&nbsp;&nbsp;&nbsp;romberg &nbsp; &nbsp; &nbsp; -- Integrate func using Romberg integration.\n\n&nbsp;Methods for Integrating Functions given fixed samples.\n\n&nbsp;&nbsp;&nbsp;trapz &nbsp; &nbsp; &nbsp; &nbsp; -- Use trapezoidal rule to compute integral from samples.\n&nbsp;&nbsp;&nbsp;cumtrapz&nbsp; &nbsp; &nbsp; -- Use trapezoidal rule to cumulatively compute integral.\n&nbsp;&nbsp;&nbsp;simps &nbsp; &nbsp; &nbsp; &nbsp; -- Use Simpson's rule to compute integral from samples.\n&nbsp;&nbsp;&nbsp;romb&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Use Romberg Integration to compute integral from\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(2**k + 1) evenly-spaced samples.\n\n&nbsp;&nbsp;&nbsp;See the special module's orthogonal polynomials (special) for Gaussian\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;quadrature roots and weights for other weighting factors and regions.\n\n&nbsp;Interface to numerical integrators of ODE systems.\n\n&nbsp;&nbsp;&nbsp;odeint&nbsp; &nbsp; &nbsp; &nbsp; -- General integration of ordinary differential equations.\n&nbsp;&nbsp;&nbsp;ode &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Integrate ODE using VODE and ZVODE routines.\n\n \n<\/pre>\n\n\n\n<p>So as you can see we have a wide variety of functions, now let us use a few of them here:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"single-integrals\">Single Integrals:<\/h3>\n\n\n\n<p>We use the quad function to calculate the single integral of a function. Numerical integrate is sometimes called quadrature and hence the name quad. The function has three parameters:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">scipy.integrate.quad(f,a,b)\n f - Function to be integrated.\n a-lower limit. \n b- upper limit.\n <\/pre>\n\n\n\n<p>Here is an example where we use this function:<\/p>\n\n\n\n<p>First, let us define a function using lambda function as shown below:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom numpy import exp  \nf= lambda x:exp(-x**2)  \n\n<\/pre><\/div>\n\n\n<p>Remember, quad() function expects us to pass a function, thus we used lambda to form a function rather than using an expression.Now to calculate the integral:<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport scipy \ni = scipy.integrate.quad(f, 0, 1)  \nprint(i)  \n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n(0.7468241328124271, 8.291413475940725e-15)\n\n <\/pre>\n\n\n\n<p>The first value is the tuple is the integral value with upper limit one and lower limit zero.Also, the second value is an estimate of the absolute error in the value of an integer.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"multiple-integrals\">Multiple Integrals<\/h3>\n\n\n\n<p>There are various functions such as dblquad(), tplquad(), and nquad() that enable us to calculate multiple integrals.the dblquad() function and tplquad() functions calculate the double and triple integrals respectively,whereas nquad performs n-fold multiple integration.<br><\/p>\n\n\n\n<p>Below we will use scipy.integrate.dblquad(func,a,b,gfun,hfun) to solve double integrals. The first argument func is the name of the function to be integrated and a and b are the lower and upper limit of the x variable.&nbsp; While gfun and hfun are names of the functions that define the lower and upper limit of the y variable.It is important to note that that limits of inner integrals must be passed functions as in the following example:<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport scipy.integrate  \nfrom numpy import exp  \nfrom math import sqrt  \nf = lambda x, y : 2*x*y  \ng = lambda x : 0  \nh = lambda y : 4*y**2  \ni = scipy.integrate.dblquad(f, 0, 0.5, g, h)  \nprint(i)\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n(0.04166666666666667, 5.491107323698757e-15)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-interpolation\"><strong>SciPy Interpolation<\/strong><\/h2>\n\n\n\n<p>Interpolation is the process of estimating unknown values that fall between known values.SciPy provides us with a sub-package scipy.interpolation which makes this task easy for us. Using this package, we can perform 1-D or univariate interpolation and Multivariate interpolation. Multivariate interpolation (spatial interpolation ) is a kind interpolation on functions that consist of more than one variables.&nbsp;<br><\/p>\n\n\n\n<p>Here is an example of 1-D interpolation where there is only variable i.e. \u2018x\u2019:<\/p>\n\n\n\n<p>First, we will define some points and plot them<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport numpy as np  \nfrom scipy import interpolate  \nimport matplotlib.pyplot as plt  \nx = np.linspace(0, 5, 10)  \ny = np.cos(x**2\/3+4) \nplt.scatter(x,y,c=&#039;r&#039;)  \nplt.show()  \n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/download.png\"><img decoding=\"async\" width=\"386\" height=\"248\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/download.png\" alt=\"scipy tutorial\" class=\"wp-image-22301\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/download.png 386w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/download-300x193.png 300w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/figure>\n\n\n\n<p>scipy.interpolation provides interp1d class which is a useful method to create a function based on fixed data points. We will create two such functions that use different techniques of interpolation. The difference will be clear to you when you see the plotted graph of both of these functions.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom scipy.interpolate import interp1d  \nimport matplotlib.pyplot as plt  \nfun1 = interp1d(x, y,kind = &#039;linear&#039;)  \nfun2 = interp1d(x, y, kind = &#039;cubic&#039;)  \n#we define a new set of input\nxnew = np.linspace(0, 4,30)  \nplt.plot(x, y, &#039;o&#039;, xnew, fun1(xnew), &#039;-&#039;, xnew, fun2(xnew), &#039;--&#039;)  \nplt.legend(&#x5B;&#039;data&#039;, &#039;linear&#039;, &#039;cubic&#039;,&#039;nearest&#039;], loc = &#039;best&#039;)  \nplt.show()\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-3.png\"><img decoding=\"async\" width=\"386\" height=\"248\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-3.png\" alt=\"\" class=\"wp-image-22304\" style=\"width:440px;height:283px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-3.png 386w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-3-300x193.png 300w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/figure>\n\n\n\n<p>In the above program, we have created two functions fun1 and fun2. The variable x contains the sample points, and variable y contains the corresponding values. The third variable kind represents the types of interpolation techniques. There are various methods of interpolation. These methods are the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Linear<\/li>\n\n\n\n<li>Nearest<\/li>\n\n\n\n<li>Zero<\/li>\n\n\n\n<li>S-linear<\/li>\n\n\n\n<li>Quadratic<\/li>\n\n\n\n<li>Cubic<\/li>\n<\/ul>\n\n\n\n<p>Now what happens when we change the input values<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom scipy.interpolate import interp1d  \nimport matplotlib.pyplot as plt  \nfun1 = interp1d(x, y,kind = &#039;linear&#039;)  \nfun2 = interp1d(x, y, kind = &#039;cubic&#039;)  \nxnew = np.linspace(3, 5,30)  \nplt.plot(x, y, &#039;o&#039;, xnew, fun1(xnew), &#039;-&#039;, xnew, fun2(xnew), &#039;--&#039;)  \nplt.legend(&#x5B;&#039;data&#039;, &#039;linear&#039;, &#039;cubic&#039;,&#039;nearest&#039;], loc = &#039;best&#039;)  \nplt.show()  \n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-4.png\"><img decoding=\"async\" width=\"386\" height=\"248\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-4.png\" alt=\"\" class=\"wp-image-22305\" style=\"width:465px;height:299px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-4.png 386w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-4-300x193.png 300w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-linalg\"><strong>SciPy linalg<\/strong><\/h2>\n\n\n\n<p>SciPy has very fast linear algebra capabilities as it is built using the optimized ATLAS (Automatically Tuned Linear Algebra Software), LAPACK(Linear Algebra Package) and BLAS(Basic Linear Algebra Subprograms) libraries. All of these linear algebra routines can operate on an object that can be converted into a two-dimensional array and also returns the output as a two-dimensional array.<br><\/p>\n\n\n\n<p>You might wonder that numpy.linalg also provides us with functions that help to solve algebraic equations, so should we use numpy.linalg or scipy.linalg? The scipy.linalg contains all the functions that are in numpy.linalg, in addition it also has some other advanced functions that are not in numpy.linalg. Another advantage of using scipy.linalg over numpy.linalg is that it is always compiled with BLAS\/LAPACK support, while for NumPy this is optional, so it's faster as mentioned before.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"solve-linear-equations\">Solve Linear Equations<\/h3>\n\n\n\n<p>We can use scipy.linalg.solve() to solve a linear equation, all we need to know is how to represent our equations in terms of vectors. Here is an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np  \nfrom scipy import linalg  \n# We are trying to solve a linear algebra system which can be given as   \n#         x + 2y - 3z = -3 \n#         2x - 5y + 4z = 13  \n#         5x + 4y - z = 5  \n#We will find values of x,y and z for which all these equations are zero\n#Also finally we will check if the values are right by substituting them\n#in the equations\n# Creating input array  \na = np.array(&#x5B;&#x5B;1, 2, -3], &#x5B;2, -5, 4], &#x5B;5, 4, -1]])  \n# Solution Array  \nb = np.array(&#x5B;&#x5B;-3], &#x5B;13], &#x5B;5]])  \n# Solve the linear algebra  \nx = linalg.solve(a, b)  \n# Print results  \nprint(x)  \n# Checking Results  \nprint(&quot;n Checking results,must be zeros&quot;)  \nprint(a.dot(x) - b)  \n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n[[ 2.]\n&nbsp;[-1.]\n&nbsp;[ 1.]]\n\n&nbsp;Checking results, Vectors must be zeros\n[[0.]\n&nbsp;[0.]\n&nbsp;[0.]]<\/pre>\n\n\n\n<p>As we can see, we got three values i.e 2,-1 and 1.So for x=2,y=-1 and z=1 the above three equations are zero as shown above.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"finding-a-determinant-of-a-square-matrix\">Finding a determinant of a square matrix&nbsp;<\/h3>\n\n\n\n<p>The determinant is a scalar value that can be computed from the elements of a square matrix and encodes certain properties of the linear transformation described by the matrix. The determinant of a matrix A is denoted det, det A, or |A|. In SciPy, this is computed using the det() function. It takes a matrix as input and returns a scalar value.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#importing the scipy and numpy packages\nfrom scipy import linalg\nimport numpy as np\n \n#Declaring the numpy array\nA = np.array(&#x5B;&#x5B;1,2,9],&#x5B;3,4,8],&#x5B;7,8,4]])\n#Passing the values to the det function\nx = linalg.det(A)\n \n#printing the result\nprint(&#039;Determinant of n{} n is {}&#039;.format(A,x))\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">Output:\nDeterminant of&nbsp;\n[[1 2 9]\n&nbsp;[3 4 8]\n&nbsp;[7 8 4]]&nbsp;\n&nbsp;is 3.999999999999986\n\n <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"eigenvalues-and-eigenvectors\">Eigenvalues and Eigenvectors<\/h3>\n\n\n\n<p>For a square matrix(A) we can find the eigenvalues (\u03bb) and the corresponding eigenvectors (v) of by considering the following relation<br><\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-5.png\"><img decoding=\"async\" width=\"303\" height=\"131\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-5.png\" alt=\"scipy tutorial\" class=\"wp-image-22307\" style=\"width:258px;height:112px\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-5.png 303w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-5-300x130.png 300w\" sizes=\"(max-width: 303px) 100vw, 303px\" \/><\/figure>\n\n\n\n<p> We can use scipy.linalg.eig to computes the eigenvalues and the eigenvectors for a particular matrix as shown below: <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#importing the scipy and numpy packages\nfrom scipy import linalg\nimport numpy as np\n \n#Declaring the numpy array\nA = np.array(&#x5B;&#x5B;2,1,-2],&#x5B;1,0,0],&#x5B;0,1,0]])\n \n#Passing the values to the eig function\nvalues, vectors = linalg.eig(A)\n \n#printing the result for eigenvalues\nprint(values)\n \n#printing the result for eigenvectors\nprint(vectors)\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n[-1.+0.j&nbsp; 2.+0.j&nbsp; 1.+0.j]\n[[-0.57735027 -0.87287156&nbsp; 0.57735027]\n&nbsp;[ 0.57735027 -0.43643578&nbsp; 0.57735027]\n&nbsp;[-0.57735027 -0.21821789&nbsp; 0.57735027]]\n\n <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-io-input-output\"><strong>SciPy IO (Input &amp; Output)<\/strong><br><\/h2>\n\n\n\n<p>The functions provided by the scipy.io package enables us to work around with different formats of files such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Matlab<\/li>\n\n\n\n<li>IDL<\/li>\n\n\n\n<li>Matrix Market<\/li>\n\n\n\n<li>Wave<\/li>\n\n\n\n<li>Arff<\/li>\n\n\n\n<li>Netcdf, etc.<\/li>\n<\/ul>\n\n\n\n<p>The functions such as loadmat(), savemat() and whosmat() can load a MATLAB file, save a MATLAB file and list variables in a MATLAB file respectively. Here is an example:<br><\/p>\n\n\n\n<p>First, save a MatLab file as test.mat which contains a structure as shown below:<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">my_struct = struct('lon', 78, 'lat', 56)<\/pre>\n\n\n\n<p>Now we can use loadmat()&nbsp; function to import this file into a python script as shown below:<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom scipy.io import loadmat\nx = loadmat(&#039;test.mat&#039;)\n#save the individual elements as python object\nlon = x&#x5B;&#039;lon&#039;]\nlat = x&#x5B;&#039;lat&#039;]\n# one-liner to read a single variable\nlon = loadmat(&#039;test.mat&#039;)&#x5B;&#039;lon&#039;]\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-ndimage\"><strong>SciPy Ndimage<\/strong><br><\/h2>\n\n\n\n<p>The SciPy provides the ndimage (n-dimensional image) package, that contains the number of general image processing and analysis functions. Some of the most common tasks in image processing are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basic manipulations \u2212 Cropping, flipping, rotating, etc.<\/li>\n\n\n\n<li>Image filtering \u2212 Denoising, sharpening, etc.<\/li>\n\n\n\n<li>Image segmentation \u2212 Labeling pixels corresponding to different objects<\/li>\n\n\n\n<li>Classification<\/li>\n\n\n\n<li>Feature extraction<\/li>\n\n\n\n<li>Registration<\/li>\n<\/ul>\n\n\n\n<p>Here are some examples in which we will apply some of these image processing techniques on the images:<\/p>\n\n\n\n<p>First, let us import an image that is already included in the SciPy package:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport scipy.misc\nimport matplotlib.pyplot as plt\nface = scipy.misc.face()#returns an image of raccoon\n#display image using matplotlib\nplt.imshow(face)\nplt.show()\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-6.png\"><img decoding=\"async\" width=\"336\" height=\"252\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-6.png\" alt=\"\" class=\"wp-image-22308\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-6.png 336w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-6-300x225.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-6-80x60.png 80w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-6-265x198.png 265w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"crop-image\">Crop image<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport scipy.misc\nimport matplotlib.pyplot as plt\nface = scipy.misc.face()#returns an image of raccoon\nlx,ly,channels= face.shape\n# Cropping\ncrop_face = face&#x5B;int(lx\/4):int(-lx\/4), int(ly\/4):int(-ly\/4)]\nplt.imshow(crop_face)\nplt.show()\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-7.png\"><img decoding=\"async\" width=\"333\" height=\"252\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-7.png\" alt=\"\" class=\"wp-image-22309\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-7.png 333w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-7-300x227.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-7-80x60.png 80w\" sizes=\"(max-width: 333px) 100vw, 333px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rotate-image\">Rotate Image<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom scipy import misc,ndimage\nimport matplotlib.pyplot as plt\nface = misc.face()\nrotate_face = ndimage.rotate(face, 180)\nplt.imshow(rotate_face)\nplt.show()\n\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-8.png\"><img decoding=\"async\" width=\"336\" height=\"252\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-8.png\" alt=\"\" class=\"wp-image-22311\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-8.png 336w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-8-300x225.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-8-80x60.png 80w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-8-265x198.png 265w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"blurring-or-smoothing-images\">Blurring or Smoothing&nbsp; Images<\/h3>\n\n\n\n<p>Here we will blur the original images using the Gaussian filter and see how to control the level of smoothness using the sigma parameter.<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom scipy import ndimage,misc\nimport matplotlib.pyplot as plt\n\nface = scipy.misc.face(gray=True)\nblurred_face = ndimage.gaussian_filter(face, sigma=3)\nvery_blurred = ndimage.gaussian_filter(face, sigma=5)\n\nplt.figure(figsize=(9, 3))\nplt.subplot(131)\nplt.imshow(face, cmap=plt.cm.gray)\nplt.axis(&#039;off&#039;)\nplt.subplot(132)\nplt.imshow(very_blurred, cmap=plt.cm.gray)\nplt.axis(&#039;off&#039;)\nplt.subplot(133)\nplt.imshow(blurred_face, cmap=plt.cm.gray)\nplt.axis(&#039;off&#039;)\n\n\nplt.subplots_adjust(wspace=0, hspace=0., top=0.99, bottom=0.01,\n                    left=0.01, right=0.99)\n\nplt.show()\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/11.png\"><img decoding=\"async\" width=\"512\" height=\"136\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/11.png\" alt=\"\" class=\"wp-image-22312\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/11.png 512w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/11-300x80.png 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure>\n\n\n\n<p>The first image is the original image followed by the blurred images with different sigma values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sharpening-images\">Sharpening images<\/h3>\n\n\n\n<p>Here we will blur the image using the Gaussian method mentioned above and then sharpen the image by adding intensity to each pixel of the blurred image.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport scipy\nfrom scipy import ndimage\nimport matplotlib.pyplot as plt\n\nf = scipy.misc.face(gray=True).astype(float)\nblurred_f = ndimage.gaussian_filter(f, 3)\n\nfilter_blurred_f = ndimage.gaussian_filter(blurred_f, 1)\n\nalpha = 30\nsharpened = blurred_f + alpha * (blurred_f - filter_blurred_f)\n\nplt.figure(figsize=(12, 4))\n\nplt.subplot(131)\nplt.imshow(f, cmap=plt.cm.gray)\nplt.axis(&#039;off&#039;)\nplt.subplot(132)\nplt.imshow(blurred_f, cmap=plt.cm.gray)\nplt.axis(&#039;off&#039;)\nplt.subplot(133)\nplt.imshow(sharpened, cmap=plt.cm.gray)\nplt.axis(&#039;off&#039;)\n\nplt.tight_layout()\nplt.show()\n\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<figure class=\"wp-block-image size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/12.png\"><img decoding=\"async\" width=\"856\" height=\"219\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/12.png\" alt=\"scipy tutorial\" class=\"wp-image-22314\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/12.png 856w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/12-300x77.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/12-768x196.png 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/12-696x178.png 696w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"edge-detection\">Edge detection<\/h3>\n\n\n\n<p>Edge detection includes a variety of mathematical methods that aim at identifying points in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The points at which image brightness changes sharply are typically organized into a set of curved line segments termed edges.<\/p>\n\n\n\n<p>Here is an example where we make a square figure and then find its edges:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmport numpy as np\nfrom scipy import ndimage\nimport matplotlib.pyplot as plt\n\nim = np.zeros((256, 256))\nim&#x5B;64:-64, 64:-64] = 1\n\nim = ndimage.rotate(im, 15, mode=&#039;constant&#039;)\nim = ndimage.gaussian_filter(im, 8)\n\nsx = ndimage.sobel(im, axis=0, mode=&#039;constant&#039;)\nsy = ndimage.sobel(im, axis=1, mode=&#039;constant&#039;)\nsob = np.hypot(sx, sy)\n\nplt.figure(figsize=(9,5))\nplt.subplot(141)\nplt.imshow(im)\nplt.axis(&#039;off&#039;)\nplt.title(&#039;square&#039;, fontsize=20)\nplt.subplot(142)\nplt.imshow(sob)\nplt.axis(&#039;off&#039;)\nplt.title(&#039;Sobel filter&#039;, fontsize=20)\nplt.show()\n\n<\/pre><\/div>\n\n\n<p><br>Output:<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/13.png\"><img decoding=\"async\" width=\"254\" height=\"144\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/13.png\" alt=\"scipy tutorial\" class=\"wp-image-22315\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-odr\"><strong>SciPy ODR<\/strong><br><\/h2>\n\n\n\n<p>Orthogonal Distance Regression (ODR) is the name given to the computational problem associated with finding the maximum likelihood estimators of parameters in measurement error models in the case of normally distributed errors. <\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-9.png\"><img decoding=\"async\" width=\"595\" height=\"463\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-9.png\" alt=\"scipy tutorial\" class=\"wp-image-22318\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-9.png 595w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-9-300x233.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/pasted-image-0-9-540x420.png 540w\" sizes=\"(max-width: 595px) 100vw, 595px\" \/><\/figure>\n\n\n\n<p>The Least square method calculates the error vertical to the line (shown by grey colour here) whereas ODR calculates the error perpendicular(orthogonal) to the line. This accounts for the error in both X and Y whereas using&nbsp; Least square method, we only consider the error in Y.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"scipy-odr-implementation-for-univariate-regression\">scipy.odr Implementation for Univariate Regression<br><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\nimport scipy.odr.odrpack as odrpack\nnp.random.seed(1)\n\nN = 100\nx = np.linspace(0,10,N)\ny = 3*x - 1 + np.random.random(N)\nsx = np.random.random(N)\nsy = np.random.random(N)\n\ndef f(B, x):\n    return B&#x5B;0]*x + B&#x5B;1]\nlinear = odrpack.Model(f)\n# mydata = odrpack.Data(x, y, wd=1.\/np.power(sx,2), we=1.\/np.power(sy,2))\nmydata = odrpack.RealData(x, y, sx=sx, sy=sy)\n\nmyodr = odrpack.ODR(mydata, linear, beta0=&#x5B;1., 2.])\nmyoutput = myodr.run()\nmyoutput.pprint()\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n\nBeta: [ 3.02012861 -0.6316873 ]\nBeta Std Error: [0.01188348 0.05616464]\nBeta Covariance: [[ 0.00067276 -0.00267083]\n&nbsp;[-0.00267083&nbsp; 0.01502795]]\nResidual Variance: 0.20990666070258754\nInverse Condition #: 0.10598108443798755\nReason(s) for Halting:\n&nbsp;&nbsp;Sum of squares convergence\n\n <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"scipy-optimize\"><strong>SciPy optimize<\/strong><br><\/h2>\n\n\n\n<p>Various commonly used optimization algorithms are included in this subpackage. It basically consists of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Unconstrained and constrained minimization of multivariate scalar functions i.e minimize (eg. BFGS, Newton Conjugate Gradient, Nelder_mead simplex, etc)<\/li>\n\n\n\n<li>Global optimization routines (eg. differential_evolution, dual_annealing, etc)<\/li>\n\n\n\n<li>Least-squares minimization and curve fitting (eg. least_squares, curve_fit, etc)<\/li>\n\n\n\n<li>Scalar univariate functions minimizers and root finders (eg. minimize_scalar and root_scalar)<\/li>\n\n\n\n<li>Multivariate equation system solvers using algorithms such as hybrid Powell, Levenberg-Marquardt.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rosenbrock-function\">Rosenbrock Function:<\/h3>\n\n\n\n<p>In mathematical optimization, the Rosenbrock function is a non-convex function, introduced by Howard H. Rosenbrock in 1960, which is used as a performance test problem for optimization algorithms. The function computed is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sum(100.0*(x[1:] - x[:-1]**2.0)**2.0 + (1 - x[:-1])**2.0<\/pre>\n\n\n\n<p>where,<\/p>\n\n\n\n<p>x is a 1-D array of points at which the Rosenbrock function is to be computed. It returns a float that is the value of the Rosenbrock function.Here is an example:<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\nfrom scipy.optimize import rosen\na = 2 * np.arange(3)\nprint(a)\nrosen(a)\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n[0 2 4]\n402.0<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"nelder-mead\">Nelder-Mead:<\/h3>\n\n\n\n<p>The Nelder\u2013Mead method (also downhill simplex method, amoeba method, or polytope method) is a commonly applied numerical method used to find the minimum or maximum of an objective function in a multidimensional space. In the following example, the minimize method is used along with the Nelder-Mead algorithm.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport numpy as np  \nimport scipy  \nfrom scipy.optimize import minimize  \n#define function f(x)  \ndef f(x):     \n    return .2*(1 - x&#x5B;0])**2  \nx1=np.array(&#x5B;1.3, 0.7, 0.8, 1.9, 1.2])\nscipy.optimize.minimize(f,x1, method=&quot;Nelder-Mead&quot;)  \n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n\nfinal_simplex: (array([[0.99999193, 0.74219995, 0.85278502, 1.96410543, 1.22139255],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1.00001128, 0.74220272, 0.85278008, 1.96402033, 1.22142657],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0.99998629, 0.74218966, 0.85279934, 1.96405769, 1.22141367],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1.00001666, 0.74218124, 0.85279 &nbsp; , 1.9640668 , 1.22140094],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[0.99998324, 0.74220839, 0.85280501, 1.96409484, 1.22137052],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[1.00001953, 0.74218806, 0.85279976, 1.96412167, 1.22137807]]), array([1.30328312e-11, 2.54555652e-11, 3.75756702e-11, 5.54966943e-11,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5.61852242e-11, 7.62918514e-11]))\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fun: 1.303283116723792e-11\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message: 'Optimization terminated successfully.'\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nfev: 136\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nit: 70\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status: 0\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success: True\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x: array([0.99999193, 0.74219995, 0.85278502, 1.96410543, 1.22139255])\n\n <\/pre>\n\n\n\n<p>So,the solution to the above problem is [0.99999193, 0.74219995, 0.85278502, 1.96410543, 1.22139255].<\/p>\n\n\n\n<p>Another optimization algorithm that needs only function calls to find the minimum is Powell\u2018s method, which is available by setting method = 'powell' in the minimize() function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"least-square-minimization\">Least Square Minimization<\/h3>\n\n\n\n<p>It is used to solve the nonlinear least-square problems bound on the variables. Given the residuals (difference between observed and predicted value of data) f(x) (an n-dimension real function of n real variables) and the loss function rho(s) (a scalar function), least_square finds a local minimum of the cost function f(x): Let's consider the following example:<br><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom scipy.optimize import least_squares  \nimport numpy as np  \ninput = np.array(&#x5B;2, 2])  \ndef rosenbrock(x):  \n   return np.array(&#x5B;10 * (x&#x5B;1] - x&#x5B;0]**3), (1 - x&#x5B;0])])  \nres = least_squares(rosenbrock, input)  \nprint(res)  \n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\n\nactive_mask: array([0., 0.])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost: 0.0\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fun: array([0., 0.])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grad: array([0., 0.])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jac: array([[-30.00000045,&nbsp; 10. &nbsp; ],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ -1.&nbsp; &nbsp; &nbsp; &nbsp; , &nbsp; 0.&nbsp; &nbsp; &nbsp; &nbsp; ]])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;message: '`gtol` termination condition is satisfied.'\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nfev: 4\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;njev: 4\n&nbsp;&nbsp;optimality: 0.0\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status: 1\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success: True\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x: array([1., 1.])\n\n <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"scipy-fsolve\">SciPy fsolve()<\/h3>\n\n\n\n<p>The scipy.optimize library provides the fsolve() function, which is used to find the root of the function. It returns the roots of the equation defined by fun(x) = 0 given a starting estimate. Consider the following example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nfrom scipy.optimize import fsolve\ndef func(x):\n    return &#x5B;x&#x5B;0] * np.cos(x&#x5B;1]) - 4,\n            x&#x5B;1] * x&#x5B;0] - x&#x5B;1] - 5]\nroot = fsolve(func, &#x5B;1, 1])\nroot\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\"> Output:\narray([6.50409711, 0.90841421])<\/pre>\n\n\n\n<p>This brings us to the end of this article where we explored the wide variety of functions provided by the SciPy library. I would recommend going through the documentation to get a more in-depth knowledge of this library. Check out this<a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/scipy-in-python\" target=\"_blank\" rel=\"noreferrer noopener\"> SciPy course<\/a> today.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"further-reading\">Further Reading<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-numpy-tutorial\/\">Python Numpy Tutorial<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/matplotlib-tutorial-for-data-visualisation\/\">Matplotlib in Python: Data Visualization Plots &amp; how to use it<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/seaborn-tutorial\/\">Seaborn Tutorial in Python For Beginners<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-data-science\/\">Data Science Tutorial For Beginners | Learn Data Science Complete Tutorial<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-pandas-tutorial\/\">A Brief Introduction to Pandas | What is Pandas in Python<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we are going to start from scratch and see how to use SciPy, scipy in python and introduce you to some of its most important features. Also, we are going to go through the different modules or sub-packages present in the SciPy package and see how they are used. What is SciPy? [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":22340,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9],"tags":[],"content_type":[],"class_list":["post-22293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SciPy Tutorial for Beginners | What is SciPy?<\/title>\n<meta name=\"description\" content=\"SciPy Tutorial for Beginners: In this SciPy tutorial, we will go through scipy which is a free and open-source Python library used for scientific computing and technical computing.\" \/>\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.mygreatlearning.com\/blog\/scipy-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SciPy Tutorial for Beginners\" \/>\n<meta property=\"og:description\" content=\"SciPy Tutorial for Beginners: In this SciPy tutorial, we will go through scipy which is a free and open-source Python library used for scientific computing and technical computing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-13T13:29:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T13:14:55+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"571\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"SciPy Tutorial for Beginners\",\"datePublished\":\"2020-11-13T13:29:51+00:00\",\"dateModified\":\"2024-04-30T13:14:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/\"},\"wordCount\":2652,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/shutterstock_114524698.jpg\",\"articleSection\":[\"Data Science and Analytics\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/\",\"name\":\"SciPy Tutorial for Beginners | What is SciPy?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/shutterstock_114524698.jpg\",\"datePublished\":\"2020-11-13T13:29:51+00:00\",\"dateModified\":\"2024-04-30T13:14:55+00:00\",\"description\":\"SciPy Tutorial for Beginners: In this SciPy tutorial, we will go through scipy which is a free and open-source Python library used for scientific computing and technical computing.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/shutterstock_114524698.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/10\\\/shutterstock_114524698.jpg\",\"width\":1000,\"height\":571},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/scipy-tutorial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data Science and Analytics\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-science\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SciPy Tutorial for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SciPy Tutorial for Beginners | What is SciPy?","description":"SciPy Tutorial for Beginners: In this SciPy tutorial, we will go through scipy which is a free and open-source Python library used for scientific computing and technical computing.","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.mygreatlearning.com\/blog\/scipy-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"SciPy Tutorial for Beginners","og_description":"SciPy Tutorial for Beginners: In this SciPy tutorial, we will go through scipy which is a free and open-source Python library used for scientific computing and technical computing.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2020-11-13T13:29:51+00:00","article_modified_time":"2024-04-30T13:14:55+00:00","og_image":[{"width":1000,"height":571,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"SciPy Tutorial for Beginners","datePublished":"2020-11-13T13:29:51+00:00","dateModified":"2024-04-30T13:14:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/"},"wordCount":2652,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg","articleSection":["Data Science and Analytics"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/","url":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/","name":"SciPy Tutorial for Beginners | What is SciPy?","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg","datePublished":"2020-11-13T13:29:51+00:00","dateModified":"2024-04-30T13:14:55+00:00","description":"SciPy Tutorial for Beginners: In this SciPy tutorial, we will go through scipy which is a free and open-source Python library used for scientific computing and technical computing.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg","width":1000,"height":571},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/scipy-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Data Science and Analytics","item":"https:\/\/www.mygreatlearning.com\/blog\/data-science\/"},{"@type":"ListItem","position":3,"name":"SciPy Tutorial for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",1000,571,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698-300x171.jpg",300,171,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698-768x439.jpg",768,439,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",1000,571,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",1000,571,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",1000,571,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",640,365,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",96,55,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/10\/shutterstock_114524698.jpg",150,86,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"In this tutorial, we are going to start from scratch and see how to use SciPy, scipy in python and introduce you to some of its most important features. Also, we are going to go through the different modules or sub-packages present in the SciPy package and see how they are used. What is SciPy?&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/22293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=22293"}],"version-history":[{"count":26,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/22293\/revisions"}],"predecessor-version":[{"id":104639,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/22293\/revisions\/104639"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/22340"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=22293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=22293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=22293"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=22293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}