I'm trying to generate a [600 x 600] numpy array that contains the sum of 10 Gaussian-like arrays (each with a randomly-generated center).
I've tried using a Gaussian filter to generate the individual Gaussian-like arrays, then summing them up, but I'm sure there's a vectorized way to approach this. Even with num_centers=10 it's slow, and I might need to sum as many as 20 Gaussians.
There is a similar question here, but it doesn't seem to have a good or conclusive answer and I'm not sure how to apply it to my problem. Sum of Gaussians into fast Numpy?
Here's what I have tried.
import numpy as np
from scipy.ndimage import gaussian_filter
import matplotlib.pyplot as plt
num_centers = 10 # number of Gaussians to sum
sigma = 100 # std. dev. of each Gaussian
result = np.zeros((600, 600))
for _ in range(num_centers):
# Pick a random coordinate within the array as the center
center = np.random.uniform(result.shape).astype(int)
# Make array with 1 at the center and 0 everywhere else
temp = np.zeros_like(result)
temp[center[0], center[1]] = 1
# Apply filter
gaussian = gaussian_filter(temp, sigma)
# Add to result
result += gaussian
# Result should look like a contour map with several hills
plt.imshow(result * 1000) # scale up to see the coloring
plt.show()
