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)= sin(x)x\frac{sin(x)}{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 numbers
x = np.linspace(-2, 2, 20)
# implementing the numpy.sinc function element-wise
myarray = np.sinc(x)
print(myarray)

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We create a variable, x , containing input values starting from -2 to 2 with an interval of 20 using the linspace() function.
  • Line 7: We implement the numpy.sinc() function on the input values. The result is assigned to a variable myarray.
  • Line 9: We print the variable myarray to the console.

Free Resources