Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Concept Entry] Python:SciPy scipy.signal: convolve() #5884

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions content/scipy/concepts/scipy-signal/terms/convolve/convolve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
Title: 'scipy.signal.convolve'
Description: 'Performs the convolution of two arrays.'
Subjects:
- 'Data Science'
- 'Computer Science'
Tags:
- 'Algorithms'
- 'Data'
- 'Signal Processing'
CatalogContent:
- 'learn-python-3'
- 'paths/computer-science'
---

**`scipy.signal.convolve`** is a function in the `scipy.signal` module that computes the convolution of two arrays. Convolution is a mathematical operation widely used in signal processing, data analysis, and machine learning. It combines two sequences to produce a third sequence, which reflects how the shape of one sequence is modified by the other.

Convolution has various applications, including filtering signals, image processing, and neural networks.

## Syntax

```python
scipy.signal.convolve(in1, in2, mode='full', method='auto')
```

### Parameters

- `in1`: Input array (array-like). The first sequence to be convolved.
- `in2`: Input array (array-like). The second sequence to be convolved.
- `mode`: (optional) Determines the size of the output:
- `'full'`: Full convolution (default).
- `'valid'`: Only parts that are fully overlapped.
- `'same'`: Output size matches the first input array.
- `method`: (optional) Specifies the method of convolution:
- `'auto'` (default): Automatically chooses the fastest method.
- `'direct'`: Uses the direct convolution method.
- `'fft'`: Uses the Fast Fourier Transform for convolution.

### Returns

- `out`: Convolved array (ndarray). The result of the convolution.

## Example

Here's an example demonstrating the use of `scipy.signal.convolve`:

```python
import numpy as np
from scipy.signal import convolve

# Define the signal and the kernel
signal = [1, 2, 3]
kernel = [0.2, 0.5, 0.2]

# Full convolution
full_result = convolve(signal, kernel, mode='full')
print("Full mode result: ", full_result)

# Same convolution
same_result = convolve(signal, kernel, mode='same')
print("Same mode result: ", same_result)

# Valid convolution
valid_result = convolve(signal, kernel, mode='valid')
print("Valid mode result: ", valid_result)
```

### Output

```
Full mode result: [0.2 0.9 1.8 1.9 0.6]
Same mode result: [0.9 1.8 1.9]
Valid mode result: [1.8]
```

In this example, the convolution computes a smoothed version of the signal, which can be useful in filtering or signal processing applications.

## Additional Resources

- **[SciPy Documentation: `scipy.signal.convolve`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve.html)**
- **[SciPy Signal Processing Module](https://docs.scipy.org/doc/scipy/reference/signal.html)**: Learn more about the broad range of signal processing capabilities in SciPy.
Loading