ndimage

Gaussian filter a 2D grid.

gaussian_filter blurs a 2D grid. Think of a tiny rainfall heatmap.

Goal

Blur a 5×5 spike and print the center.

from scipy import ndimage
grid = np.zeros((5, 5))
grid[2, 2] = 10
print(ndimage.gaussian_filter(grid, sigma=1).round(2))
from scipy import ndimage
grid = np.arange(16, dtype=float).reshape(4, 4)
print(ndimage.uniform_filter(grid, size=3).round(1))
from scipy import ndimage
grid = np.zeros((6, 6))
grid[1:3, 1:3] = 1
print(ndimage.binary_dilation(grid).astype(int))
from scipy import ndimage
grid = np.zeros((20, 20))
grid[10, 10] = 1
plt.imshow(ndimage.gaussian_filter(grid, 2))
plt.axis('off')
plt.show()
print('ok')