Skip to content

Commit 8b15475

Browse files
committed
Update translation: lectures/scipy.md
1 parent 4d9ab6e commit 8b15475

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

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)