2.8. 创建幻灯片¶
我们可以标记一个 notebook,然后用它来创建幻灯片。例如,这是从 Markdown 源文件生成的幻灯片。下面我们通过一个例子来解释如何操作。这是一个带有标记的 Markdown 文件,用于生成幻灯片。
# Data Manipulation
## Getting Started
To start, we can use `arange` to create a row vector `x`
containing the first 12 integers starting with 0,
though they are created as floats by default.
A tensor represents a (possibly multi-dimensional) array of numerical values. We can access a tensor's *shape*.
```{.python .input}
import numpy as np
x = np.arange(12)
x
```
Many more operations can be applied elementwise,
including unary operators like exponentiation.
```{.python .input}
np.exp(x)
```
Even when shapes differ, we can still perform elementwise operations
by invoking the *broadcasting mechanism*.
```{.python .input}
a = np.arange(3).reshape(3, 1)
b = np.arange(2).reshape(1, 2)
a, b
```
上述代码块将生成 2 张幻灯片。第一张幻灯片包含以下内容:
# Data Manipulation
A tensor represents a (possibly multi-dimensional) array of numerical values. We can access a tensor's *shape*.
```{.python .input}
import numpy as np
x = np.arange(12)
x
```
你可以看到我们自动复制了一级标题和代码块。此外,我们还复制了 和
之间的文本,而删除了所有其他内容。
第二张幻灯片包含以下内容:
Many operations can be applied elementwise,
e.g. `exp`
```{.python .input}
np.exp(x)
```
Even when shapes differ, we can still perform elementwise operations
```{.python .input}
a = np.arange(3).reshape(3, 1)
b = np.arange(2).reshape(1, 2)
a, b
```
首先你可以看到,这三对标记(,
)、(,
)和 (```) 之间的所有文本都被保留了。在这里,表示开始一张新的幻灯片,而
表示继续当前幻灯片。(一级标题会开始一张新的幻灯片,所以我们在上一个区块中使用了
)。此外,
~~` 表示文本只出现在幻灯片中,而不会出现在普通的 notebook、HTML 或 PDF 中。
其次,我们在最后一个代码块之前没有开始新的幻灯片,也就是说,没有一级标题,也没有(,
)标记对,所以最后两个代码块被合并到了同一张幻灯片中。