solutions update from 7ed0c61

This commit is contained in:
rougier
2026-04-29 06:34:30 +00:00
committed by github-actions[bot]
parent 7ed0c61ccd
commit 6cedcb2ad9
4 changed files with 231 additions and 215 deletions

View File

@@ -565,10 +565,18 @@ for index in np.ndindex(Z.shape):
```python
X, Y = np.meshgrid(np.linspace(-1,1,10), np.linspace(-1,1,10))
D = np.sqrt(X*X+Y*Y)
X, Y = np.meshgrid(np.linspace(-1, 1, 10), np.linspace(-1, 1, 10))
sigma, mu = 1.0, 0.0
G = np.exp(-( (D-mu)**2 / ( 2.0 * sigma**2 ) ) )
G = np.exp(-((X - mu) ** 2 + (Y - mu) ** 2) / (2.0 * sigma**2))
print(G)
# Another solution using the fact that a 2D Gaussian is separable
# Author: Nin17
x = np.linspace(-1, 1, 10)
y = np.linspace(-1, 1, 10)
gx = np.exp(-((x - mu) ** 2 / (2.0 * sigma**2)))
gy = np.exp(-((y - mu) ** 2 / (2.0 * sigma**2)))
G = gy[:, None] * gx[None, :]
print(G)
```
#### 57. How to randomly place p elements in a 2D array? (★★☆)