2021-05-18

本文详细介绍了PyTorch中Tensor的数据类型及其特点,包括各种浮点数、整数、复数类型以及布尔类型,并提供了每种类型对应的CPU和GPU张量实例。此外,还简要说明了如何通过Tensor.item()方法获取张量的Python标准数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tnesor 常用的数据类型和函数

数据类型:

TORCH.TENSOR

torch.Tensor is a multi-dimensional matrix containing elements of a single data type.

Torch defines 10 tensor types with CPU and GPU variants which are as follows:

Data type

dtype

CPU tensor

GPU tensor

32-bit floating point

torch.float32 or torch.float

torch.FloatTensor

torch.cuda.FloatTensor

64-bit floating point

torch.float64 or torch.double

torch.DoubleTensor

torch.cuda.DoubleTensor

16-bit floating point 1

torch.float16 or torch.half

torch.HalfTensor

torch.cuda.HalfTensor

16-bit floating point 2

torch.bfloat16

torch.BFloat16Tensor

torch.cuda.BFloat16Tensor

32-bit complex

torch.complex32

  

64-bit complex

torch.complex64

  

128-bit complex

torch.complex128 or torch.cdouble

  

8-bit integer (unsigned)

torch.uint8

torch.ByteTensor

torch.cuda.ByteTensor

8-bit integer (signed)

torch.int8

torch.CharTensor

torch.cuda.CharTensor

16-bit integer (signed)

torch.int16 or torch.short

torch.ShortTensor

torch.cuda.ShortTensor

32-bit integer (signed)

torch.int32 or torch.int

torch.IntTensor

torch.cuda.IntTensor

64-bit integer (signed)

torch.int64 or torch.long

torch.LongTensor

torch.cuda.LongTensor

Boolean

torch.bool

torch.BoolTensor

torch.cuda.BoolTensor

Tensor.item() → number

Returns the value of this tensor as a standard Python number

pytorch 下安装Tensorflow的解决方法

pip --default-timeout=100 install tensorflow -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值