import torch
a = torch.tensor([3,2,3,4])
b = a.view(2,2)
c = a.resize(2,2)
d = a.resize_(2,2)
print(id(a.storage()))
print(id(b.storage()))
print(id(c.storage()))
print(id(d.storage()))
第一次跑步
2356950450056
2356950450056
2356950450056
2356950450056
第二次运行
2206021857352
2206301638600
2206021857352
2206301638600
为什么我有时会变,但有时不会变,我在网上搜索了很长时间。但是没有用。请帮助或尝试给出一些如何实现这一点的想法。(为我糟糕的英语道歉) 提前感谢。
您无需查看或调整对象大小即可观察此行为,对同一对象调用
storage
可以返回不同的id:这是因为python存储对象是when calling
.storage()
构造的相关问题 更多 >
编程相关推荐