提交 6ea7277c 编写于 作者: 考拉不是大叔's avatar 考拉不是大叔

finish tensor chapter

上级 60c1ebd0
......@@ -260,3 +260,33 @@ print(f"n: {n}")
t: tensor([2., 2., 2., 2., 2.])
n: [2. 2. 2. 2. 2.]
```
**2. 由Numpy array数组转为张量**
```python
n = np.ones(5)
t = torch.from_numpy(n)
```
修改`Numpy array`数组的值,则张量值也会随之改变。
```python
np.add(n, 1, out=n)
print(f"t: {t}")
print(f"n: {n}")
```
显示:
```python
t: tensor([2., 2., 2., 2., 2.], dtype=torch.float64)
n: [2. 2. 2. 2. 2.]
```
**脚本的总运行时间**:(0 分钟 0.045 秒)
[下载 Python 源码:`tensor_tutorial.py`](https://pytorch.org/tutorials/_downloads/092fba3c36cb2ab226bfdaa78248b310/tensor_tutorial.py)
[下载 Jupyter 笔记本:`tensor_tutorial.ipynb`](https://pytorch.org/tutorials/_downloads/3c2b25b8a9f72db7780a6bf9b5fc9f62/tensor_tutorial.ipynb)
[由 Sphinx 画廊](https://sphinx-gallery.readthedocs.io)生成的画廊
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册