Discrete convolution can be performed via the Toeplitz matrix, as shown below (Wiki article):
Note that this is not the exact same form as as the general Toeplitz matrix, but it has experienced various shifts and zero-paddings.
Is there a way to achieve this in numpy purely based on roll
, hstack
etc., i.e. without using any for
loops? I have tried all sorts of shifts but I can't really get it in to the form shown above.
t = toeplitz( a , b ) returns a nonsymmetric Toeplitz matrix with a as its first column and b as its first row. b is cast to the numerictype of a . If one of the arguments of toeplitz is a built-in data type, it is cast to the data type of the fi object.
toeplitz( c , r ) generates a nonsymmetric Toeplitz matrix having c as its first column and r as its first row. If the first elements of c and r are different, toeplitz issues a warning and uses the first element of the column. example. toeplitz( r ) generates a symmetric Toeplitz matrix if r is real.
Toeplitz matrices are used to model systems that posses shift invariant properties. The property of shift invariance is evident from the matrix structure itself. Since we are modelling a Linear Time Invariant system[1], Toeplitz matrices are our natural choice.
Yes, you can use scipy.linalg.toeplitz
:
import numpy as np
from scipy import linalg
h = np.arange(1, 6)
padding = np.zeros(h.shape[0] - 1, h.dtype)
first_col = np.r_[h, padding]
first_row = np.r_[h[0], padding]
H = linalg.toeplitz(first_col, first_row)
print(repr(H))
# array([[1, 0, 0, 0, 0],
# [2, 1, 0, 0, 0],
# [3, 2, 1, 0, 0],
# [4, 3, 2, 1, 0],
# [5, 4, 3, 2, 1],
# [0, 5, 4, 3, 2],
# [0, 0, 5, 4, 3],
# [0, 0, 0, 5, 4],
# [0, 0, 0, 0, 5]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With