PyTorch:type(a)、a.type和a.type()之间的差异

PyTorch:type(a)、a.type和a.type()之间的差异,pytorch,Pytorch,假设a是张量,那么两者之间的区别是什么: 类型(a) a、 类型 a、 类型() 我找不到区分这些的文档。type(a)-返回类类型 type(a) - returns the class type a.type - returns built method type a.type() - return the data type >>> a = torch.Tensor() >>> type(a) <class 'torch.Tensor'>

假设a是张量,那么两者之间的区别是什么:

类型(a)

a、 类型

a、 类型()

我找不到区分这些的文档。

type(a)-返回类类型
type(a) - returns the class type
a.type - returns built method type
a.type() - return the data type

>>> a = torch.Tensor()
>>> type(a)
<class 'torch.Tensor'>
>>> a.type
<built-in method type of Tensor object at 0x7f6a0acfc140>
>>> a.type()    
'torch.FloatTensor'                                                     
a、 type-返回生成的方法类型 a、 type()-返回数据类型 >>>a=火炬张量() >>>类型(a) >>>a.类型 >>>a.类型() “火炬,漂浮张量”
是python的内置方法

  • 它将返回对象的类型。像
x.type()
)是pytorch的内置方法

  • 它将返回存储在tensor中的数据类型。像火炬双张量一样

编辑:

关于
x.type()
vs
x.type
-
当您使用括号
x.type()
编写函数名时,它将实际执行函数并返回其值。而没有括号
x.type
它只是对函数的引用。

此外,对于数据类型,float和tensor.float有什么区别?