Skip to content

Commit 03e65bb

Browse files
authored
🌐 [translation-sync] [scipy.md] Update np.random → Generator API (#120)
* Update translation: lectures/scipy.md * Update translation: .translate/state/scipy.md.yml
1 parent c2ce8ef commit 03e65bb

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

.translate/state/scipy.md.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source-sha: cfedc1a06bbefe20d23924d26aef437a968ab2da
2-
synced-at: "2026-03-20"
3-
model: unknown
4-
mode: RESYNC
1+
source-sha: fb75a07e49cbec97c2c3e698a81ee008203b1fab
2+
synced-at: "2026-05-08"
3+
model: claude-sonnet-4-6
4+
mode: UPDATE
55
section-count: 8
6-
tool-version: 0.13.1
6+
tool-version: 0.14.1

lectures/scipy.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ a = np.identity(3)
124124

125125
### متغیرهای تصادفی و توزیع‌ها
126126

127-
به یاد بیاورید که `numpy.random` توابعی را برای تولید متغیرهای تصادفی فراهم می‌کند
127+
به یاد بیاورید که `numpy.random` ابزارهایی را برای تولید متغیرهای تصادفی فراهم می‌کند
128128

129129
```{code-cell} python3
130-
np.random.beta(5, 5, size=3)
130+
rng = np.random.default_rng()
131+
rng.beta(5, 5, size=3)
131132
```
132133

133134
این یک نمونه از توزیع با تابع چگالی زیر را وقتی `a, b = 5, 5` تولید می‌کند
@@ -208,8 +209,8 @@ plt.show()
208209
```{code-cell} python3
209210
from scipy.stats import linregress
210211
211-
x = np.random.randn(200)
212-
y = 2 * x + 0.1 * np.random.randn(200)
212+
x = rng.standard_normal(200)
213+
y = 2 * x + 0.1 * rng.standard_normal(200)
213214
gradient, intercept, r_value, p_value, std_err = linregress(x, y)
214215
gradient, intercept
215216
```
@@ -592,8 +593,9 @@ $$ \mathbb E \max\{ S_n - K, 0 \}
592593
در اینجا یک راه‌حل آورده شده است:
593594

594595
```{code-cell} ipython3
596+
rng = np.random.default_rng()
595597
M = 10_000_000
596-
S = np.exp(μ + σ * np.random.randn(M))
598+
S = np.exp(μ + σ * rng.standard_normal(M))
597599
return_draws = np.maximum(S - K, 0)
598600
P = β**n * np.mean(return_draws)
599601
print(f"The Monte Carlo option price is {P:3f}")
@@ -648,4 +650,4 @@ bisect(f, 0, 1)
648650
```
649651

650652
```{solution-end}
651-
```
653+
```

0 commit comments

Comments
 (0)