pytorch-tensor创建,类型转换


1.查看数据类型
常用类型有 : torch.IntTensor、 torch.FloatTensor
torch.Tensor是默认的tensor类型(torch.FloatTensor)的简称
tensor.dtype
2.类型转换

方法一:简单后缀转换

tensor.int()
tensor.float()
tensor.double()

方法二:使用torch.type()函数

tensor.type(torch.FloatTensor)

方法三:使用type_as(tensor)将tensor转换为指定tensor的类型

3.tensor创建--指定维度和数据类型
torch.IntTensor(3,4).zero_()
torch.Tensor(3,4).zero_()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM