How do I generate 2D Gaussian noise with a specified spatial frequency and standard…
- User
How do I generate 2D Gaussian noise with a specified spatial frequency and standard deviation
Assistant
You can generate 2D Gaussian noise with a specified spatial frequency and standard deviation like this:
import numpy as np def gaussian_noise(shape, freq, std): """Generate 2D Gaussian noise with specified spatial frequency and std dev""" x, y = np.meshgrid(np.linspace(0, 1, shape[0]), np.linspace(0, 1, shape[1])) sin_map = np.sin(2 * np.pi * freq * x) * np.sin(2 * np.pi * freq * y) noise = std * np.random.randn(*shape) * sin_map return noiseThis does the following:
- Create x and y coordinate grids using np.meshgrid
- Generate a sinusoidal map using the specified frequency. This gives the spatial frequency.
- Generate random Gaussian noise with the specified std dev
- Multiply the sinusoidal map and the noise to get correlated Gaussian noise with the desired frequency and std dev.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.