What is the use of scipy.interpolate.interp1d class of SciPy python library?

ScipyScientific ComputingProgramming

<p>The <strong><em>scipy.interpolate.interp1d(x, y, kind, axis, copy, bounds_error, fill_value, assumesorted)</em></strong> class of SciPy library, as name implies, is used to interpolate a 1-Dimensional function. Here, x and y are the arrays of values which are used to approximate some function, say f; y=f(x). The output of this class is a function whose call method uses interpolation to find the value of new points.</p><p>Below is given the detailed explanation of its parameters &minus;</p><h2>Parameters</h2><ul class="list"><li><strong>x &minus; (N,) <em>array_like</em></strong><p>It is a 1-dimensional array of real values.</p></li><li><p><strong>y &minus; (&hellip;,N,&hellip;) <em>array_like</em></strong></p><p>It is a N-dimensional array of real values. The condition is that the length of y along with the interpolation axis should be equal to the length of x.</p></li><li><p><strong>kind &minus; <em>str or int, optional</em></strong></p></li></ul><p>As name implies, this parameter specifies the kind of interpolation. It can of string or integer. If you are going to provide string, then it must be one of the following &minus;</p><ul class="list"><li><p>linear</p></li><li><p>nearest</p></li><li><p>nearest-up</p></li><li><p>zero</p></li><li><p>slinear</p></li><li><p>quadratic</p></li><li><p>cubic</p></li><li><p>previous</p></li><li><p>next</p></li></ul><p>The default value of this parameter is &lsquo;linear&rsquo;.</p><ul class="list"><li><p><strong>axis &minus; <em>int, optional</em></strong></p><p>As name implies, this parameter specifies the axis of y along which we need to interpolate.</p></li><li><p><strong>copy &minus; <em>bool, optional</em></strong></p><p>This parameter, if true, is used to make the internal copies of x and y. On the other hand, if the value of this parameter is false, the references of x and y are used. The default value of this parameter is &lsquo;True&rsquo;.</p></li><li><p><strong>bounds_error &minus; <em>bool, optional</em></strong></p><p>This parameter, if true, is used to raise a ValueError on attempting interpolation on a value outside the range of x. and y. On the other hand, if the value of this parameter is false, out of bounds values are assigned fill_value. By default, this parameter will raise an error unless fill_value = &ldquo;extrapolate&rdquo;.</p></li><li><strong>fill_value &minus; <em>array-like or (array-like, array_like) or &ldquo;extrapolate&rdquo;, optional</em></strong></li></ul><p>There are following three cases for fill_value parameter&minus;</p><ul class="list"><li><p><strong>ndarray or float</strong>&minus; If this would be a ndarry or float then the value will be used to fill in for requested points outside of the range of data. The default value is NaN.</p></li><li><p><strong>Two-element tuple</strong>&minus; If this would be a two-element tuple, both elements will be used in different ways. The first element will be used as a fill value for x_new &lt; x[0]. The second element will be used for x_new &gt; x[-1].</p></li><li><p><strong>Extrapolate</strong>&minus; If we provide &lsquo;extrapolate&rsquo;, the points outside the range of data will be generalized or extrapolated.</p></li><li><strong>assume_sorted &minus; <em>bool, optional</em></strong><p>If the value of this parameter is true, the values of x should be an array of monotonically increasing values. On the other hand, if the value of this parameter is false, the values of x can be in any order and the values will be sorted first as well.</p></li></ul>
raja
Updated on 14-Dec-2021 11:48:18

Advertisements