Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: torch.tensor创建的torch张量与原numpy数组是不共享内存的 #1342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions chapter_preliminaries/ndarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ computation(X, Y)

:begin_tab:`pytorch`
将深度学习框架定义的张量[**转换为NumPy张量(`ndarray`)**]很容易,反之也同样容易。
torch张量和numpy数组将共享它们的底层内存,就地操作更改一个张量也会同时更改另一个张量。
通过torch.numpy将torch张量转换为numpy数组,或是通过torch.from_numpy将numpy数组转换为torch张量,torch张量和numpy数组将共享它们的底层内存,就地操作更改一个张量也会同时更改另一个张量。而torch.tensor是为numpy数组新建一个副本,二者不共享内存
:end_tab:

```{.python .input}
Expand All @@ -614,7 +614,7 @@ type(A), type(B)
```{.python .input}
#@tab pytorch
A = X.numpy()
B = torch.tensor(A)
B = torch.from_numpy(A)
type(A), type(B)
```

Expand Down
Loading