Detailed explanation of correlation in Python numpy

Look at the code and see this method. Record it. This is the link to their official website np.correlate.

What is unclear is actually the dot multiplication of two arrays. The different modes are misplaced dot multiplications. Just look at the code.

a is the original array, v is the filter, corresponding to multiplication

import numpy as np

mode0 = 'same'
mode1 = 'valid'
mode2 = 'full'

a = [1, 2, 3]
v = [1, 2]

print(np.correlate(a, v, mode0))
print(np.correlate(a, v, mode1))
print(np.correlate(a, v, mode2))

# 结果
[2 5 8]
[5 8]
[2 5 8 3]

insert image description here

a = [1, 2, 3]
v = [1, 2, 3]

print(np.correlate(a, v, mode0))
print(np.correlate(a, v, mode1))
print(np.correlate(a, v, mode2))

# 结果
[ 8 14  8]
[14]
[ 3  8 14  8  3]
a = [1, 2, 3, 4]
v = [1, 2]

print(np.correlate(a, v, mode0))
print(np.correlate(a, v, mode1))
print(np.correlate(a, v, mode2))

# 结果
[ 2  5  8 11]
[ 5  8 11]
[ 2  5  8 11  4]

Guess you like

Origin blog.csdn.net/u010095372/article/details/132183363