Pytorch 张量 Tensors 操作

Pytorch 张量 Tensors 操作

判断 obj 是否是一个 pytorch 张量

torch.is_tensor
torch.is_tensor(obj)

判断 obj 是否是一个 pytorch storage 对象

torch.is_storage
torch.is_storage(obj)

查询张量中的元素的个数:

torch.numel( obj) -> int
Example:
a = torch.randn(1, 2, 3, 4, 5)
torch.numel(a) -> 120
a = torch.zeros(4, 4)
torch.numel(a) -> 16

设置打印选项

torch.set_printoptions(precision=None,  threshold=None, edgeitems=None, linewidth=None, profile=None)

参数:

  • precision - 浮点数输出的精度位数(默认8位)
  • threshold - 阈值,触发汇总显示而不是完全显示(repr)的数组元素的总数(默认是1000)
  • edgeitems - 汇总显示中,每维两端显示的项数(默认值是3)
  • linewidth - 用于插入行间隔的每行字符数(默认是80)
  • profile - 打印完全默认值。可以覆盖上述所有选项

猜你喜欢

转载自blog.csdn.net/weixin_43915090/article/details/134759001
今日推荐