

{"id":78572,"date":"2020-09-12T09:00:33","date_gmt":"2020-09-12T03:30:33","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=78572"},"modified":"2021-05-09T13:13:24","modified_gmt":"2021-05-09T07:43:24","slug":"scipy-interpolation","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/","title":{"rendered":"SciPy Interpolation"},"content":{"rendered":"<p>The SciPy library is generally for mathematical and statistical computations. There are sub-packages in the library that manage more specific functionalities. There is the scipy.interpolation that has specific usage in the field of statistics. Let us learn more about SciPy Interpolation.<\/p>\n<h2>SciPy Interpolation<\/h2>\n<p>The process of interpolation means locating a value between two points. We can consider the two points to be on a line or over a curve. The meaning of the word interpolation is split as \u201cinter\u201d which means \u201center\u201d, that means estimating a set of data by looking into it.<\/p>\n<p>Interpolation is basically looking between two data points for the estimation of the value in between the two. It is generally used in any field requiring value estimation from a set of data.<\/p>\n<p>Interpolation is carried out using the scipy.interpoation package. Its working is dependent on other libraries like numpy and matplotlib.<br \/>\nWe create an array and then apply the interpolation functions.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\nx = np.linspace(0,3,15)\r\ny = np.sin(x**3\/9)\r\nprint (x)\r\nprint(y)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[0. 0.21428571 0.42857143 0.64285714 0.85714286 1.07142857<br \/>\n1.28571429 1.5 1.71428571 1.92857143 2.14285714 2.35714286<br \/>\n2.57142857 2.78571429 3. ]<br \/>\n[0. 0.00109329 0.00874624 0.02951466 0.06991376 0.13623681<br \/>\n0.23396278 0.36627253 0.53098857 0.7152709 0.88814574 0.99332329<br \/>\n0.94973234 0.67401073 0.14112001]<\/div>\n<p>We have used the linspace() and sin() function to generate two sets of arrays. Now we will use the plot function to check the value plot. We have to import the matplotlib package.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import matplotlib.pyplot as plt  \r\nplt.plot(x,y,'o')  \r\nplt.show() \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82086\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code.png\" alt=\"\" width=\"377\" height=\"251\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code.png 377w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code-300x200.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code-150x100.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code-272x182.png 272w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/a><\/p>\n<h2>1D Interpolation in SciPy<\/h2>\n<p>The interpolation module provides the interp1d class that is meant to create functions on the basis of the input data set. We can create new functions with different interpolation techniques. There is a variety of interpolation techniques:<\/p>\n<ul>\n<li>Linear<\/li>\n<li>Nearest<\/li>\n<li>Cubic<\/li>\n<li>Zero<\/li>\n<li>S-linear<\/li>\n<li>Quadratic<\/li>\n<\/ul>\n<p>The syntax for 1 D interpolation is:<br \/>\n<strong>func = interp1d(x, y ,kind = &#8216; &#8216;)<\/strong><\/p>\n<p>The x denotes the data points, y denotes the data values and the third parameter kid represents the type of interpolation technique.<br \/>\nWe plot two new functions using the previous data set.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">from scipy.interpolate import interp1d  \r\nf1 = interp1d(x, y,kind = 'linear')\r\nf2 = interp1d(x, y, kind = 'cubic')\r\nplt.plot(x, y, 'o', x, f1(x), '-', x, f2(x), '--')  \r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82087\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code2.png\" alt=\"1 D interpolation in SciPy\" width=\"363\" height=\"256\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code2.png 363w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code2-300x212.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code2-150x106.png 150w\" sizes=\"auto, (max-width: 363px) 100vw, 363px\" \/><\/a><\/p>\n<h2>Splines in SciPy<\/h2>\n<p>It is a tool for smoothening of the curves. It is an ancient method where pins were placed along the curve for obtaining smooth curves. The spline technique is like using a flexible strip at selective points to obtain a smooth curve.<\/p>\n<p>We make the curve smooth in two steps. First, we make the spline representation of the curve. Then we smoothen the curves at the desired points.<\/p>\n<p>We use the splrep() function to represent a two-dimensional curve. The default order of the spline is cubic which can change by changing the input parameters.<\/p>\n<h3>Univariate Spline<\/h3>\n<p>It is a class in SciPy for function creation with fixed data points.<\/p>\n<p>The syntax is as follows:<\/p>\n<p><strong>scipy.interpolate.UnivariateSpline(x, y, w = None, bbox = [None, None], k = 3, s = None, ext = 0, check_finite = False).<\/strong><\/p>\n<ul>\n<li>The parameter w specifies the weight, which is a positive value.<\/li>\n<li>The s value defines the number of points for smoothening.<\/li>\n<li>The value of \u2018k\u2019 defines the degree of smoothening.<\/li>\n<li>The parameter \u2018ext\u2019 defines the extrapolation mode.<\/li>\n<li>The \u2018check_finite\u2019 value is to make sure the values are only finite.<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import matplotlib.pyplot as plt  \r\nimport numpy as np  \r\nfrom scipy.interpolate import UnivariateSpline  \r\nx = np.linspace(0, 3,15)  \r\ny = np.sin(x**3\/9)  \r\nspl = UnivariateSpline(x, y)\r\nxs = np.linspace(0, 3, 1000)\r\nplt.plot(xs, spl(xs), 'g', lw = 3)\r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-82088\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code3.png\" alt=\"Spline in SciPy\" width=\"365\" height=\"252\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code3.png 365w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code3-300x207.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/code3-150x104.png 150w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>SciPy includes all the necessary scientific and mathematical functions. The library contains additional sub-packages of which Interpolation is one. The package has very useful functions for statistical operations.<\/p>\n<p>These are actually useful when determining an intermediate data value from a given data set. It has its use in many sectors including business and many other scientific fields.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SciPy library is generally for mathematical and statistical computations. There are sub-packages in the library that manage more specific functionalities. There is the scipy.interpolation that has specific usage in the field of statistics.&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":82073,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22401],"tags":[23242],"class_list":["post-78572","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","tag-scipy-interpolation"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SciPy Interpolation - DataFlair<\/title>\n<meta name=\"description\" content=\"SciPy Interpolation - Interpolation is defined as finding a value between two points on a line or a curve.It is carried out using scipy.interpoation package\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SciPy Interpolation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"SciPy Interpolation - Interpolation is defined as finding a value between two points on a line or a curve.It is carried out using scipy.interpoation package\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-12T03:30:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:43:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/SciPy-Interpolation.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SciPy Interpolation - DataFlair","description":"SciPy Interpolation - Interpolation is defined as finding a value between two points on a line or a curve.It is carried out using scipy.interpoation package","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:\/\/data-flair.training\/blogs\/scipy-interpolation\/","og_locale":"en_US","og_type":"article","og_title":"SciPy Interpolation - DataFlair","og_description":"SciPy Interpolation - Interpolation is defined as finding a value between two points on a line or a curve.It is carried out using scipy.interpoation package","og_url":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-09-12T03:30:33+00:00","article_modified_time":"2021-05-09T07:43:24+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/SciPy-Interpolation.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"SciPy Interpolation","datePublished":"2020-09-12T03:30:33+00:00","dateModified":"2021-05-09T07:43:24+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/"},"wordCount":531,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/SciPy-Interpolation.jpg","keywords":["scipy interpolation"],"articleSection":["NumPy Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/","url":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/","name":"SciPy Interpolation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/SciPy-Interpolation.jpg","datePublished":"2020-09-12T03:30:33+00:00","dateModified":"2021-05-09T07:43:24+00:00","description":"SciPy Interpolation - Interpolation is defined as finding a value between two points on a line or a curve.It is carried out using scipy.interpoation package","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/scipy-interpolation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/SciPy-Interpolation.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/09\/SciPy-Interpolation.jpg","width":1200,"height":628,"caption":"SciPy Interpolation"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/scipy-interpolation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"NumPy Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/numpy\/"},{"@type":"ListItem","position":3,"name":"SciPy Interpolation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/78572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=78572"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/78572\/revisions"}],"predecessor-version":[{"id":92991,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/78572\/revisions\/92991"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/82073"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=78572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=78572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=78572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}