numpy.interp() function Python (original) (raw)
Last Updated : 24 Sep, 2024
numpy.interp()
function returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x.
**Syntax : numpy.interp(x, xp, fp, left = None, right = None, period = None)
**Parameters :
**x : [array_like] The x-coordinates at which to evaluate the interpolated values.
**xp: [1-D sequence of floats] The x-coordinates of the data points, must be increasing if the argument period is not specified. Otherwise, xp is internally sorted after normalizing the periodic boundaries with xp = xp % period.
**fp : [1-D sequence of float or complex] The y-coordinates of the data points, same length as xp.
**left : [optional float or complex corresponding to fp] Value to return for x < xp[0], default is fp[0].
****right :** [optional float or complex corresponding to fp] Value to return for x > xp[-1], default is fp[-1].
**period : [None or float, optional] A period for the x-coordinates. This parameter allows the proper interpolation of angular x-coordinates. Parameters left and right are ignored if the period is specified.**Return : [float or complex or ndarray] The interpolated values, same shape as x.
**Code #1 :
Python `
Python program explaining
numpy.interp() function
importing numpy as geek
import numpy as geek
x = 3.6 xp = [2, 4, 6] fp = [1, 3, 5]
gfg = geek.interp(x, xp, fp)
print (gfg)
`
**Output :
2.6
**Code #2 :
Python `
Python program explaining
numpy.interp() function
importing numpy as geek
import numpy as geek
x = [0, 1, 2.5, 2.72, 3.14] xp = [2, 4, 6] fp = [1, 3, 5]
gfg = geek.interp(x, xp, fp)
print (gfg)
`
**Output :
[1. 1. 1.5 1.72 2.14]
Similar Reads
- numpy.i0() function | Python numpy.i0() function is the modified Bessel function of the first kind, order 0. it's usually denoted by I0. Syntax : numpy.i0(x) Parameters : x : [array_like, dtype float or complex] Argument of the Bessel function. Return : [ndarray, shape = x.shape, dtype = x.dtype] The modified Bessel function ev 1 min read
- numpy.ix_() function | Python numpy.ix_() function construct an open mesh from multiple sequences. This function takes N 1-D sequences and returns N outputs with N dimensions each, such that the shape is 1 in all but one dimension and the dimension with the non-unit shape value cycles through all N dimensions. Syntax : numpy.ix_ 1 min read
- numpy.iinfo() function – Python numpy.iinfo() function shows machine limits for integer types. Syntax : numpy.iinfo(dtype) Parameters : dtype : [integer type, dtype, or instance] The kind of integer data type to get information about. Return : Machine limits for integer types. Code #1 : # Python program explaining # numpy.iinfo() 1 min read
- numpy.imag() function - Python numpy.imag() function return the imaginary part of the complex argument. Syntax : numpy.imag(arr) Parameters : arr : [array_like] Input array. Return : [ndarray or scalar] The imaginary component of the complex argument. If val is real, the type of val is used for the output. If val has complex elem 1 min read
- numpy.intersect1d() function in Python numpy.intersect1d() function find the intersection of two arrays and return the sorted, unique values that are in both of the input arrays. Syntax: numpy.intersect1d(arr1, arr2, assume_unique = False, return_indices = False) Parameters : arr1, arr2 : [array_like] Input arrays. assume_unique : [bool] 1 min read
- numpy.in1d() function in Python numpy.in1d() function test whether each element of a 1-D array is also present in a second array and return a boolean array the same length as arr1 that is True where an element of arr1 is in arr2 and False otherwise. Syntax : numpy.in1d(arr1, arr2, assume_unique = False, invert = False) Parameters 2 min read
- numpy.info() function in Python In Numpy we can get all the information about the function, class, or module like what will the parameter and what will be the type of the return value with the help of numpy.info() function. This function returns the help information for a function, class, or module. Syntax: numpy.info(numpy.info(o 1 min read
- Python | numpy.issubdtype() function numpy.issubdtype() function is used to determine whether the first argument is a typecode lower/equal in type hierarchy from second argument.If the first argument is lower or equal it returns true, otherwise it returns false. Syntax : numpy.issubdtype(arg1, arg2) Parameters : arg1, arg2 : [dtype_lik 1 min read
- Python | numpy.issubsctype() function numpy.issubsctype() function is used to determine whether the first argumentis a subclass of the second argument.If the first argument is a subclass of the second argument it returns true, otherwise it returns false. Syntax : numpy.issubsctype(arg1, arg2) Parameters : arg1, arg2 : dtype or dtype spe 1 min read
- numpy.inner() in python numpy.inner(arr1, arr2): Computes the inner product of two arrays. Parameters : arr1, arr2 : array to be evaluated. Return: Inner product of the two arrays. Code #1 : # Python Program illustrating # numpy.inner() method import numpy as geek # Scalars product = geek.inner(5, 4) print("inner Prod 1 min read