结论
torch.FloatTensor()默认生成32位浮点数,dtype 为 torch.float32
或 torch.float
验证
>>> tensor = torch.FloatTensor([[1,2],[3,4]])
>>> print tensor
tensor([[1., 2.],
[3., 4.]])
>>> print tensor.dtype
torch.float32
官网各类tensor对应数据类型如下:
https://pytorch.org/docs/stable/tensors.html?highlight=torch%20floattensor
Data type | dtype | CPU tensor | GPU tensor |
---|---|---|---|
32-bit floating point |
|
|
|
64-bit floating point |
|
|
|
16-bit floating point 1 |
|
|
|
16-bit floating point 2 |
|
|
|
32-bit complex |
| ||
64-bit complex |
| ||
128-bit complex |
| ||
8-bit integer (unsigned) |
|
|
|
8-bit integer (signed) |
|
|
|
16-bit integer (signed) |
|
|
|
32-bit integer (signed) |
|
|
|
64-bit integer (signed) |
|
|
|
Boolean |
|
|
|
quantized 8-bit integer (unsigned) |
|
| / |
quantized 8-bit integer (signed) |
|
| / |
quantized 32-bit integer (signed) |
|
| / |
quantized 4-bit integer (unsigned) 3 |
|
| / |