温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

torch中如何使用new()方法

发布时间:2021-08-05 17:50:36 来源:亿速云 阅读:225 作者:Leah 栏目:大数据

这篇文章将为大家详细讲解有关torch中如何使用new()方法,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

Microsoft Windows [版本 10.0.18363.1256](c) 2019 Microsoft Corporation。保留所有权利。

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 0x0000028DEB88D330>>>>>>> a = torch.zeros(3,4)>>> a
tensor([[0., 0., 0., 0.],[0., 0., 0., 0.],[0., 0., 0., 0.]])>>> a = torch.randn(3,4)>>> 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.manual_seed(seed=20200910)<torch._C.Generator object at 0x0000028DEB88D330>>>> a = torch.randn(3,4)>>> 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]])>>>>>> a.new(4)tensor([0., 0., 0., 0.])>>>>>> a.new()tensor([])>>>>>> a.new(5,6)tensor([[ 1.8370e+25,  1.4603e-19,  0.0000e+00,  0.0000e+00,  2.1019e-44,  0.0000e+00],[-3.0652e-36,  4.5916e-41,  0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00],[ 0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00],[ 0.0000e+00,  0.0000e+00,  0.0000e+00,  0.0000e+00,  5.2751e-11,  0.0000e+00],[ 2.8026e-45,  1.1625e+33, -5.1397e-05,  4.5916e-41,  0.0000e+00,  0.0000e+00]])>>>KeyboardInterrupt>>>KeyboardInterrupt>>>>>>>>> a.new(5,2)tensor([[1.7743e+28, 1.3458e-14],[1.2689e+31, 3.2745e-12],[7.5555e+31, 1.2705e+31],[3.2611e-12, 7.5555e+31],[1.2705e+31, 1.7225e+22]])>>> a.new(3)tensor([0., 0., 0.])>>>>>>

关于torch中如何使用new()方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI