Pytorch 理解张量赋值
假设我为一批3幅图像创建一个占位符-Pytorch 理解张量赋值,pytorch,variable-assignment,tensor,Pytorch,Variable Assignment,Tensor,假设我为一批3幅图像创建一个占位符- batch = torch.zeros(3, 3, 256, 256, dtype=torch.uint8) 我有我的虚拟形象- image = torch.randint(size = (3,256,256), low=0, high=256) 那么我会的- batch[0] = image 我无法理解以下输出- (一) 这不应该是真的,因为两者都包含对同一张量对象“图像”的引用吗 (二) 既然“批处理”和“映像”共享相同的底层存储,为什么在打印“映
batch = torch.zeros(3, 3, 256, 256, dtype=torch.uint8)
我有我的虚拟形象-
image = torch.randint(size = (3,256,256), low=0, high=256)
那么我会的-
batch[0] = image
我无法理解以下输出-
(一)
这不应该是真的,因为两者都包含对同一张量对象“图像”的引用吗
(二)
既然“批处理”和“映像”共享相同的底层存储,为什么在打印“映像”的相应元素时,批处理[0][0][0][0]中的更改没有反映出来
谢谢大家! 您可能需要阅读答案中的链接
id(batch[0]) == id(image)
out: False
id(batch.storage()) == id(image.storage())
out: True
batch[0][0][0][0] = 5
print(image[0][0][0])
out: 171