What is the numpy.sinc() function in NumPy?
Overview
In NumPy, the numpy.sinc() function is used to compute the normalized sinc function.
Mathematically:
Sinc(x)=
Syntax
numpy.sinc(x)
Syntax for the numpy.sinc() function
Parameter
This function takes a single parameter value, x, which is the input array of values to be calculated.
Return value
This function returns an array of the same shape as the input array holding the results for each of the elements.
Example
import numpy as np# creating a evenly spaced numbersx = np.linspace(-2, 2, 20)# implementing the numpy.sinc function element-wisemyarray = np.sinc(x)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create a variable,
x, containing input values starting from-2to2with an interval of20using thelinspace()function. - Line 7: We implement the
numpy.sinc()function on the input values. The result is assigned to a variablemyarray. - Line 9: We print the variable
myarrayto the console.