pyhiperta.utils.convolve
Convolution utilities for hexagonal lattices.
Functions:
| Name | Description |
|---|---|
convolve_view |
Read-only view into |
convolve_view
Read-only view into a that has stencil_shape extra dimensions for each part of a that a stencil
of shape stencil_shape would operate on.
Directly taken from https://stackoverflow.com/questions/43086557/convolve2d-just-by-using-numpy
It allows to view the sub-parts of a of shape stencil_shape without copying or duplicating a's data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
The array to get the view in. |
required |
stencil_shape
|
Tuple[int, ...]
|
The shape of the stencil that we would want to operate on |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Read-only view in |
Examples:
>>> a = np.arange(55 * 55).reshape((55, 55))
>>> stencil = np.array([[0, 1], [1, 0]])
>>> convolve_view(a, stencil.shape).shape
(54, 54, 2, 2)
>>> convolve_view(a, stencil.shape)[0, 0, :, :] # left/high-most 2x2 part of `a`.
...
array([[ 0, 1],
[55, 56]])
>>> convolve_view(a, stencil.shape)[1, 1, :, :]
...
array([[ 56, 57],
[111, 112]])
Raises:
| Type | Description |
|---|---|
ValueError
|
If |