当前位置: 代码迷 >> 综合 >> tensor数据类型转换
  详细解决方案

tensor数据类型转换

热度:112   发布时间:2023-10-17 05:12:04.0

tensor数据类型转换

torch.long() 将tensor转换为long类型

torch.half() 将tensor转换为半精度浮点类型

torch.int() 将该tensor转换为int类型

torch.double() 将该tensor转换为double类型

torch.float() 将该tensor转换为float类型

torch.char() 将该tensor转换为char类型

torch.byte() 将该tensor转换为byte类型

torch.short() 将该tensor转换为short类型

几种数据类型转换的方式如下:

a = t.Tensor(2, 3)
b = a.float()
c = a.type_as(b)
d = a.new(2, 3)
  相关解决方案