Convolve two N-dimensional arrays as a LinearOperator.
Note that this only implements the “same” convolution mode seen in other functions. This is often the desired mode for linear systems since the problem does not alter dimensions when the convolution is applied.
For this operator to work, the number of dimensions in the kernel must match the number of fields in the shape tuple.
| Parameters: | kernel : ndarray
shape : tuple
order = {‘C’, ‘F’, ‘A’}, optional
|
|---|---|
| Returns: | LinearOperator
|
| Raises: | ValueError
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import convolve
>>> A = np.linspace(1,9,9).reshape(3,3)
>>> kernel = np.array([[-1, 1]])
>>> C = convolve(kernel, (3, 3))
>>> C(np.ravel(A))
array([-1., -1., -1., -4., -1., -1., -7., -1., -1.])
>>> C(np.ravel(A)).reshape(3,3)
array([[-1., -1., -1.],
[-4., -1., -1.],
[-7., -1., -1.]])
Approximate the derivative with a central difference.
| Parameters: | derivative : int
points : int
shape : tuple
step: tuple, optional
order = {‘C’, ‘F’, ‘A’}, optional
|
|---|---|
| Returns: | LinearOperator
|
| Raises: | ValueError
|
See also
Examples
>>> import numpy as np
>>> from pyop.operators import gradient
>>> grad = gradient(1, 3, (5,6))
>>> laplace = gradient(2, 3, (5,6), step=(0.5,2))
>>> A = np.indices((5,6)).sum(0)**2 / 2.
>>> grad(np.ravel(A)).reshape(5,6)
array([[ 0.5 , 2. , 4.25, 7. , 10.25, 5. ],
[ 2. , 4. , 6. , 8. , 10. , -0.25],
[ 4.25, 6. , 8. , 10. , 12. , -2. ],
[ 7. , 8. , 10. , 12. , 14. , -4.25],
[ 4. , 1. , -0.25, -2. , -4.25, -32. ]])
>>> laplace(np.ravel(A)).reshape(5,6)
array([[ 2.125, 4.25 , 2.25 , -3.75 , -13.75 , -32.25 ],
[ 4.25 , 4.25 , 4.25 , 4.25 , 4.25 , -1.875],
[ 4.125, 4.25 , 4.25 , 4.25 , 4.25 , -3.75 ],
[ 3.75 , 4.25 , 4.25 , 4.25 , 4.25 , -5.875],
[ -46.875, -67.75 , -93.75 , -123.75 , -157.75 , -208.25 ]])