Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .translate/state/functions.md.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source-sha: 1b356ab5e60d8f6939446fd5f47c243593a2abd3
synced-at: "2026-05-04"
model: claude-sonnet-4-6
source-sha: aacff3815993e8bea8db7b63df72a0a038e220c1
synced-at: "2026-08-05"
model: claude-sonnet-5
mode: UPDATE
section-count: 7
tool-version: 0.14.1
tool-version: 0.25.0
8 changes: 4 additions & 4 deletions .translate/state/numpy.md.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source-sha: a2b929f15e703b6942e8b80a29011c51f234b1e0
synced-at: "2026-05-13"
model: claude-sonnet-4-6
source-sha: aacff3815993e8bea8db7b63df72a0a038e220c1
synced-at: "2026-08-05"
model: claude-sonnet-5
mode: UPDATE
section-count: 8
tool-version: 0.15.0
tool-version: 0.25.0
8 changes: 4 additions & 4 deletions .translate/state/pandas.md.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source-sha: 811accdd4ed8803df3a7123ada3b560bc3110712
synced-at: "2026-06-19"
model: claude-sonnet-4-6
source-sha: aacff3815993e8bea8db7b63df72a0a038e220c1
synced-at: "2026-08-05"
model: claude-sonnet-5
mode: UPDATE
section-count: 5
tool-version: 0.15.0
tool-version: 0.25.0
8 changes: 4 additions & 4 deletions .translate/state/python_by_example.md.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source-sha: 3241a07f00b1fb4d2bebc6989d1f480847e08e31
synced-at: "2026-04-25"
model: claude-sonnet-4-6
source-sha: aacff3815993e8bea8db7b63df72a0a038e220c1
synced-at: "2026-08-05"
model: claude-sonnet-5
mode: UPDATE
section-count: 6
tool-version: 0.14.1
tool-version: 0.25.0
3 changes: 1 addition & 2 deletions lectures/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ quad(lambda x: x**3, 0, 2)

## 应用


### 随机抽取

再次考虑 {doc}`前一讲 <python_by_example>` 中的以下代码
Expand Down Expand Up @@ -465,7 +464,7 @@ def x(t):

* 帧是存储给定函数调用的局部变量的地方
* 栈是用于处理函数调用的内存
* 一个先进后出(FILO)队列
* 一种后进先出(LIFO)数据结构

这个例子有些刻意,因为第一个(迭代)解通常比递归解更受欢迎。

Expand Down
12 changes: 6 additions & 6 deletions lectures/numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ z

另请参阅 `np.asarray`,它执行类似的功能,但不会对已在 NumPy 数组中的数据进行独立复制。

要从包含数值数据的文本文件中读取数组数据,使用 `np.loadtxt`——详情请参阅[文档](https://numpy.org/doc/stable/reference/routines.io.html)。
要从包含数值数据的文本文件中读取数组数据,使用 `np.loadtxt` ——详情请参阅[文档](https://numpy.org/doc/stable/reference/routines.io.html)。

### 数组索引

Expand Down Expand Up @@ -1263,7 +1263,7 @@ class DiscreteRV:

然而,这里有一个问题。

假设在创建 `discreteRV` 实例后修改了 `q`,例如
假设在创建 `DiscreteRV` 实例后修改了 `q`,例如

```{code-cell} python3
q = (0.1, 0.9)
Expand Down Expand Up @@ -1394,7 +1394,7 @@ F.plot(ax)

在本练习中,尝试使用 `for` 循环来复现以下广播操作的结果。

**第一部分**:尝试使用 `for` 循环复现以下简单示例,并将你的结果与下面的广播操作进行比较。
**第 1 部分**:尝试使用 `for` 循环复现以下简单示例,并将你的结果与下面的广播操作进行比较。

```{code-cell} python3

Expand All @@ -1413,7 +1413,7 @@ tags: [hide-output]
print(A)
```

**第二部分**:继续复现以下广播操作的结果。同时,比较广播和你实现的 `for` 循环的速度。
**第 2 部分**:继续复现以下广播操作的结果。同时,比较广播和你实现的 `for` 循环的速度。

对于本练习的这一部分,你可以使用 `quantecon` 库中的 `tic`/`toc` 函数来计时执行。

Expand Down Expand Up @@ -1453,7 +1453,7 @@ print(B)
:class: dropdown
```

**第一部分解答**
**第 1 部分解答**

```{code-cell} python3
rng = np.random.default_rng(123)
Expand Down Expand Up @@ -1483,7 +1483,7 @@ print(np.array_equal(A, C))
```


**第二部分解答**
**第 2 部分解答**

```{code-cell} python3

Expand Down
8 changes: 4 additions & 4 deletions lectures/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ df.apply(update_row, axis=1)

```{code-cell} ipython3
# 将所有小数四舍五入到2位小数
df.map(lambda x : round(x,2) if type(x)!=str else x)
df.map(lambda x : round(x,2) if not isinstance(x, str) else x)
```

**应用:缺失值插补**
Expand All @@ -414,8 +414,8 @@ df
```{code-cell} ipython3
# 将所有NaN值替换为0
def replace_nan(x):
if type(x)!=str:
return 0 if np.isnan(x) else x
if not isinstance(x, str):
return 0 if pd.isna(x) else x
else:
return x

Expand Down Expand Up @@ -547,7 +547,7 @@ r = requests.get('https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e
* 切换到另一台机器
* 通过阅读[文档](https://requests.readthedocs.io/en/latest/)解决代理问题

假设一切正常,你现在可以使用调用 `requests.get('https://research.stlouisfed.org/fred2/series/UNRATE/downloaddata/UNRATE.csv')` 返回的 `source` 对象继续操作
假设一切正常,你现在可以根据调用 `requests.get(url)` 返回的数据来构建 `source` 对象

```{code-cell} ipython3
url = 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e9f0&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1318&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=UNRATE&scale=left&cosd=1948-01-01&coed=2024-06-01&line_color=%234572a7&link_values=false&line_style=solid&mark_type=none&mw=3&lw=2&ost=-99999&oet=99999&mma=0&fml=a&fq=Monthly&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2024-07-29&revision_date=2024-07-29&nd=1948-01-01'
Expand Down
4 changes: 2 additions & 2 deletions lectures/python_by_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ plt.plot(ϵ_values)
plt.show()
```

while 循环将持续执行由缩进分隔的代码块,直到条件(```i < ts_length```)被满足。
while 循环将持续执行由缩进分隔的代码块,只要条件(`i < ts_length`)被满足。

在本例中,程序将持续向列表 ```ϵ_values``` 添加值,直到 ```i``` 等于 ```ts_length```:
在本例中,程序将持续向列表 `ϵ_values` 添加值,直到 `i` 等于 `ts_length`:

```{code-cell} python3
i == ts_length # while 循环的终止条件
Expand Down
Loading