【发布时间】:2021-08-11 13:52:13
【问题描述】:
什么是使用torch-tensor的好方法:复制或创建新的张量?速度呢? 目标是在每次调用方法时获得一个具有恒定大小的新零张量。
class CopyOrCreateZeros:
def __init__(self):
self.fx = torch.zeros((800, 600))
pass
def method(self, x):
""" this method will be used many ofter e.g. in loop """
# do something
new_x1 = torch.copy(self.fx)
new_x2 = torch.clone(self.fx)
new_x3 = x.new_zeros()
new_x4 = torch.zeros_like(x)
new_x5 = torch.zeros()
【问题讨论】:
标签: pytorch copy new-operator tensor