每个torch.Tensor都有torch.dtype, torch.device,和torch.layout

torch.dtype

torch.dtype是表示torch.Tensor的数据类型的对象。PyTorch有八种不同的数据类型:

Data type dtype Tensor types
32-bit floating point torch.float32 or torch.float torch.*.FloatTensor
64-bit floating point torch.float64 or torch.double torch.*.DoubleTensor
16-bit floating point torch.float16 or torch.half torch.*.HalfTensor
8-bit integer (unsigned) torch.uint8 torch.*.ByteTensor
8-bit integer (signed) torch.int8 torch.*.CharTensor
16-bit integer (signed) torch.int16 or torch.short torch.*.ShortTensor
32-bit integer (signed) torch.int32 or torch.int torch.*.IntTensor
64-bit integer (signed) torch.int64 or torch.long torch.*.LongTensor

使用方法:

>>> x = torch.Tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
>>> print x.type()
torch.FloatTensor

torch.layout

torch.layout表示torch.Tensor内存布局的对象。目前,我们支持torch.strided(dense Tensors)并为torch.sparse_coo(sparse COO Tensors)提供实验支持。

torch.strided代表密集张量,是最常用的内存布局。每个strided张量都会关联 一个torch.Storage,它保存着它的数据。这些张力提供了多维度, 存储的strided视图。Strides是一个整数型列表:k-th stride表示在张量的第k维从一个元素跳转到下一个元素所需的内存。这个概念使得可以有效地执行多张量。

例:

>>> x = torch.Tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
>>> x.stride()
(5, 1)>>> x.t().stride()
(1, 5)

关于torch.sparse_coo张量的更多信息,请参阅torch.sparse。

《转:pytorch中文学习文档》

原创文章,转载请注明 :pytorch使用torch.dtype、torch.device和torch.layout管理数据类型属性 - pytorch中文网

005.torch.dtype相关推荐

  1. pytorch torch.Tensor.new_ones()(返回一个与size大小相同的用1填充的张量。 默认返回的Tensor具有与此张量相同的torch.dtype和torch.device)

    from https://pytorch.org/docs/1.1.0/tensors.html?highlight=new_ones#torch.Tensor.new_ones new_ones(s ...

  2. pytorch(2)Tensor创建和获取tensor的size信息、torch.dtype、torch.device、torch.layout

    获取tensor的size信息 >>> import torch >>> from torch.autograd import Variable >>& ...

  3. numpy和torch数据操作对比

    对numpy和torch数据操作进行对比,避免遗忘. ndarray和tensor import torch import numpy as npnp_data = np.arange(6).resh ...

  4. torch.mean

    自己测试的可以: import torchx=torch.arange(256).view(4,4,4,4).float() x_mean=torch.mean(x,axis=[2,3],keepdi ...

  5. tensor torch 构造_TORCH.TENSOR

    tensor 是一个由单一数据类型数据组成的多维矩阵 torch 定义了8种 CPU 张量和 GPU张量 tensor可以用torch.tensor(data)创建,data可以是 python li ...

  6. torch.nn.Module()

    torch.nn.Module() 如果自己想研究,官方文档 它是所有的神经网络的根父类! 你的神经网络必然要继承! 模块也可以包含其他模块,允许将它们嵌套在树结构中.所以呢,你可以将子模块指定为常规 ...

  7. pytorch torch.randn

    应用 >>> torch.randn(2, 3) tensor([[ 1.5954, 2.8929, -1.0923],[ 1.1719, -0.4709, -0.1996]]) A ...

  8. pytorch torch.randint

    应用 >>> torch.randint(10, (2, 2)) tensor([[0, 2],[5, 5]]) API torch.randint(low=0, high, siz ...

  9. pytorch torch.rand

    应用 Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1) &g ...

最新文章

  1. c#sort升序还是降序_C#中对数组或集合进行升序或降序排序
  2. SAP 开发陷阱一箩筐(01)——创建了函数组却无法激活
  3. pycharm如何修改背景成护眼色和字体大小
  4. php imagevue,Imagevue 2.1.4 正式注册版(PHP Flash相册源代码下载)
  5. QT绘制带有数据源的图表
  6. 如何C#中实现在TreeView查找某一节点
  7. qpython手机kivy库_QPython Android Kivy,从python脚本启动python脚本
  8. JDK8新特性(五)之Stream流介绍和获取方式
  9. opencv有基于c语言的教程吗_VS2019配置opencv详细图文教程和测试代码的实现
  10. 怎样在EDIUS中进行快速抠图
  11. android7.1获取存储权限,Android外部存储
  12. memtest86内存测试工具介绍
  13. 微信小程序全栈开发实践 第一章 重新认识微信小程序、及新功能介绍
  14. Linux工作目录切换命令
  15. 知足而乐,不知足亦乐
  16. Striped64 深入源码解析
  17. Dispose 和 GC 注意点
  18. cuBLAS使用(4)
  19. Android CardView 不显示阴影
  20. C语言幻方矩阵的求解

热门文章

  1. hnust 好友互动标识
  2. iOS模拟器管理工具simctl了解一下
  3. c#中int类型转换为short类型
  4. linux(Ubuntu)下的wifi热点安装配置------hostapd-2.0
  5. linux桌面没有我的电脑,电脑不显示桌面,没有图标,右击桌面所有地方也没有用,怎么解决?...
  6. 操作wordpress要掌握php吗,wordpress好学吗
  7. 新浪微博、微信朋友圈、qq空间分享---微信朋友圈
  8. repo upload 时报错
  9. Nginx - 深入理解nginx的处理请求、进程关系和配置文件重载
  10. 房子室内应该怎么画?如何画好窗帘和窗户?