tensor 张量

tensor 张量,第1张

tensor 张量

在数学中,一个单独的数可以成为标量,一列或者一行数组可以称为向量,一个二维数组成为矩阵,矩阵中的每一个元素都可以被行和列的索引唯一确定,如果数组的维度超过2,那么我们可以称该数组为张量。但是在 pytorch 中,张量属于一种数据结构,它可以是一个标量、一个向量、一个矩阵,甚至是更高维的数组,所以 pytorch 中 tensor 和 numpy 库中的数组 ndarray 非常相似,在使用时也会经常将 pytorch 的相关计算和优化都是在 tensor 的基础上完成的。

在 torch 中 CPU 和 GPU 张量分别有 8 种数据类型

数据类型dtypeCPU tensorGPU tensor32 位浮点型torch.float32 或 torch.floattorch.FloatTensortorch.cuda.FloatTensor64 位浮点型torch.float64 或 torch.doubletorch.DoubleTensortorch.cuda.DoubleTensor16 位浮点型torch.float16 或 torch.halftorch.HalfTensortorch.cuda.HalfTensor8 位无符号整型torch.uint8torch.ByteTensortorch.cuda.ByteTensor8 位有符号整型torch.int8torch.CharTensortorch.cuda.CharTensor16 位有符号整型torch.int16 或 torch.shorttorch.ShortTensortorch.cuda.ShortTensor32 位有符号整型torch.int32 或 torch.inttorch.IntTensortorch.cuda.IntTensor64 位有符号整型torch.int64 或 torch.longtorch.LongTensortorch.cuda.LongTensor

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5711020.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存