- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Return the discrete linear convolution of two one-dimensional sequences in Python

To return the discrete linear convolution of two one-dimensional sequences, use the numpy.convolve() method in Python Numpy.

The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal. In probability theory, the sum of two independent random variables is distributed according to the convolution of their individual distributions. If v is longer than a, the arrays are swapped before computation. The method returns the Discrete, linear convolution of a and v. The 1st parameter, a is the first one-dimensional input array. The 2nd parameter, v is the second one-dimensional input array. The 3rd parameter, mode is optional, with values full’, ‘valid’, ‘same’

## Steps

At first, import the required libraries −

import numpy as np

Creating two numpy One-Dimensional array using the array() method −

arr1 = np.array([1, 2, 3]) arr2 = np.array([0, 1, 0.5])

Display the arrays −

print("Array1...

",arr1) print("

Array2...

",arr2)

Check the Dimensions of both the arrays −

print("

Dimensions of Array1...

",arr1.ndim) print("

Dimensions of Array2...

",arr2.ndim)

Check the Shape of both the arrays −

print("

Shape of Array1...

",arr1.shape) print("

Shape of Array2...

",arr2.shape)

To return the discrete linear convolution of two one-dimensional sequences, use the numpy.convolve() method −

print("

Result....

",np.convolve(arr1, arr2 ))

## Example

import numpy as np # Creating two numpy One-Dimensional array using the array() method arr1 = np.array([1, 2, 3]) arr2 = np.array([0, 1, 0.5]) # Display the arrays print("Array1...

",arr1) print("

Array2...

",arr2) # Check the Dimensions of both the arrays print("

Dimensions of Array1...

",arr1.ndim) print("

Dimensions of Array2...

",arr2.ndim) # Check the Shape of both the arrays print("

Shape of Array1...

",arr1.shape) print("

Shape of Array2...

",arr2.shape) # To return the discrete linear convolution of two one-dimensional sequences, use the numpy.convolve() method in Python Numpy print("

Result....

",np.convolve(arr1, arr2 ))

## Output

Array1... [1 2 3] Array2... [0. 1. 0.5] Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (3,) Shape of Array2... (3,) Result.... [0. 1. 2.5 4. 1.5]

- Related Questions & Answers
- Return the discrete linear convolution of two one-dimensional sequences with mode in Python
- Return the discrete linear convolution of two one-dimensional sequences and return the middle values in Python
- Return the discrete linear convolution of two one-dimensional sequences and get where they overlap in Python
- Return the outer product of two masked One-Dimensional Numpy arrays
- Return the dot product of One-Dimensional vectors in Python
- Return the inner product of two masked One-Dimensional arrays in Numpy
- Time Convolution and Frequency Convolution Properties of Discrete-Time Fourier Transform
- Compute the determinant of a Two-Dimensional array in linear algebra in Python
- Get the Outer product of two One-Dimensional arrays in Python
- Get the Kronecker product of two One-Dimensional Arrays in Python
- Get the Inner product of two One-Dimensional arrays in Python
- Get the Inner product of a One-Dimensional and a Two-Dimensional array in Python
- C# Program to return the difference between two sequences
- Split one-dimensional array into two-dimensional array JavaScript
- Difference Between One-Dimensional (1D) and Two-Dimensional (2D) Array