我注意到,您经常可以从torch模块本身调用使用张量的方法,或者将其作为torch张量实例上的绑定方法调用。
例如:
import torch
my_tens = torch.ones((3,2))
another_tens = torch.ones((3,2))
res_tens = my_tens==another_tens
# both are equivalent:
torch.all(res_tens, dim=1)
res_tens.all(dim=1)类似地,.sum()和其他方法的工作方式相同。为什么会这样呢?使用其中一种方法有什么好处吗?
发布于 2020-04-16 15:35:28
这两个选项是等效的,并且“在幕后”运行相同的实现。您可以使用任何对您更方便的方法,并使代码更具可读性。
https://stackoverflow.com/questions/61178850
复制相似问题