pytorch系列文档之API(torch:Tensors详解)

torch.is_tensor(obj)#是pytorch tensor时返回true torch.is_storage(obj)#是pytorch 存储对象时返回true torch.is_complex(input) -> (bool)#是复杂数据类型时返回true,例如,torch.complex64, and torch.complex128 torch.is_floating_point(input) -> (bool)#是否浮点数数据类型,torch.float64, torch.float32 and torch.float16等torch.set_default_dtype(d)#设置默认数据类型为d,d指的是torch.float32、torch.float64等数据类型。 torch.get_default_dtype() → torch.dtype#返回当前默认数据类型torch.set_default_tensor_type(t)#设置默认tensor类型为t,t指的是torch.FloatTensor、torch.DoubleTensor等 torch.numel(input) → int#获得input中所有元素的个数,例如4x4的tensor中包含元素16个

torch.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, sci_mode=None) #打印设置,就是输出tensor时的设置 #precision 精度,默认小数点后4位 #threshold 触发显示摘要而不是整个时的值,默认1000 #edgeitems 显示摘要时,设置在摘要的每一维前面显示几个值,后面显示几个值,默认3 #linewidth用于插入换行符的每行字符数(默认= 80)。阈值矩阵将忽略此参数 #profile 配置文件,应该就是显示效果,可选default, short, full #sci_mode 是否科学计数法,Enable (True) or disable (False) scientific notation

torch.set_flush_denormal(mode) → bool#设置是否清洗cpu上的非正常浮点数示例: >>> torch.set_flush_denormal(True) True >>> torch.tensor([1e-323], dtype=torch.float64) tensor([ 0.], dtype=torch.float64) >>> torch.set_flush_denormal(False) True >>> torch.tensor([1e-323], dtype=torch.float64) tensor(9.88131e-324 * [ 1.0000], dtype=torch.float64)

    推荐阅读