Skip to content

Commit 12a3b6b

Browse files
authored
🌐 [translation-sync] [scipy.md] Update np.random → Generator API (#63)
* Update translation: lectures/scipy.md * Update translation: .translate/state/scipy.md.yml
1 parent 98192ec commit 12a3b6b

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

.translate/state/scipy.md.yml

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

lectures/scipy.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ SciPy 中有用的部分是其子包中的功能
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` 时,这从具有以下密度函数的分布中生成一个样本
@@ -212,13 +213,13 @@ plt.show()
212213
```{code-cell} python3
213214
from scipy.stats import linregress
214215
215-
x = np.random.randn(200)
216-
y = 2 * x + 0.1 * np.random.randn(200)
216+
x = rng.standard_normal(200)
217+
y = 2 * x + 0.1 * rng.standard_normal(200)
217218
gradient, intercept, r_value, p_value, std_err = linregress(x, y)
218219
gradient, intercept
219220
```
220221

221-
要查看完整列表,请参阅[文档](https://docs.scipy.org/doc/scipy/reference/stats.html#statistical-functions-scipy-stats)
222+
要查看完整列表,请参阅 [文档](https://docs.scipy.org/doc/scipy/reference/stats.html#statistical-functions-scipy-stats)
222223

223224
## 根与不动点
224225

@@ -591,8 +592,9 @@ $$ \mathbb E \max\{ S_n - K, 0 \}
591592
以下是一种解答:
592593

593594
```{code-cell} ipython3
595+
rng = np.random.default_rng()
594596
M = 10_000_000
595-
S = np.exp(μ + σ * np.random.randn(M))
597+
S = np.exp(μ + σ * rng.standard_normal(M))
596598
return_draws = np.maximum(S - K, 0)
597599
P = β**n * np.mean(return_draws)
598600
print(f"The Monte Carlo option price is {P:3f}")
@@ -607,9 +609,9 @@ print(f"The Monte Carlo option price is {P:3f}")
607609
```{exercise}
608610
:label: sp_ex1
609611
610-
在{ref}`本讲座 <functions>`中,我们讨论了{ref}`递归函数调用 <recursive_functions>`的概念。
612+
{ref}`本讲座 <functions>` 中,我们讨论了 {ref}`递归函数调用 <recursive_functions>` 的概念。
611613
612-
尝试编写上面{ref}`描述的 <bisect_func>`自制二分函数的递归实现。
614+
尝试编写上面 {ref}`描述的 <bisect_func>` 自制二分函数的递归实现。
613615
614616
用函数 {eq}`root_f` 对其进行测试。
615617
```
@@ -647,4 +649,4 @@ bisect(f, 0, 1)
647649
```
648650

649651
```{solution-end}
650-
```
652+
```

0 commit comments

Comments
 (0)