torch.mean()和mean(dim=None, keepdim=False)的使用举例怎么分析,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
代码实验展示:
Microsoft Windows [版本 10.0.18363.1256](c) 2019 Microsoft Corporation。保留所有权利。 C:/Users/chenxuqi>C:/Users/chenxuqi>conda activate ssd4pytorch2_2_0(ssd4pytorch2_2_0) C:/Users/chenxuqi>python Python 3.7.7 (default, May 6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.>>> import torch>>> torch.manual_seed(seed=20200910)<torch._C.Generator object at 0x000001F58010D330>>>> a = torch.randn(4, 3)>>> a tensor([[ 0.2824, -0.3715, 0.9088],[-1.7601, -0.1806, 2.0937],[ 1.0406, -1.7651, 1.1216],[ 0.8440, 0.1783, 0.6859]])>>> torch.mean(a)tensor(0.2565)>>>>>> a tensor([[ 0.2824, -0.3715, 0.9088],[-1.7601, -0.1806, 2.0937],[ 1.0406, -1.7651, 1.1216],[ 0.8440, 0.1783, 0.6859]])>>> torch.mean(a, 1)tensor([0.2732, 0.0510, 0.1324, 0.5694])>>> torch.mean(a, 0)tensor([ 0.1017, -0.5347, 1.2025])>>>>>> torch.mean(input=a, dim=0, keepdim=False)tensor([ 0.1017, -0.5347, 1.2025])>>>>>> torch.mean(input=a, dim=1, keepdim=False)tensor([0.2732, 0.0510, 0.1324, 0.5694])>>>>>> torch.mean(input=a, dim=0, keepdim=True)tensor([[ 0.1017, -0.5347, 1.2025]])>>> torch.mean(input=a, dim=1, keepdim=True)tensor([[0.2732],[0.0510],[0.1324],[0.5694]])>>>>>>>>>
关于torch.mean()和mean(dim=None, keepdim=False)的使用举例怎么分析问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/240184.html