YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别

区别:

1. torch.tensor.size() 可用通过 :torch.tensor.size(具体的某一子张量矩阵下标) :来获取对应的具体的某一子张量矩阵的维度结构;


2. torch.tensor.shape 不可用通过 :torch.tensor.shape (具体的某一子张量矩阵下标) :来获取对应的具体的某一子张量矩阵的维度结构,

但是可以通过:torch.tensor.shape (具体的某一子张量矩阵下标) 来获取对应的具体的某一子张量矩阵的具体内容;


源代码:

import torcha1 = torch.zeros(0)
a2 = torch.zeros(1)
a3 = torch.zeros(1, 1)
a4 = torch.zeros(2, 3)
a5 = torch.zeros(2, 3, 5)print('a1 = ', a1)
print('a2 = ', a2)
print('a3 = ', a3)
print('a4 = ', a4)
print('a5 = ', a5)# JY Lin YDOOK
# Print the size of tensor valuables
print()
print('a1.size() = ', a1.size())
print('a2.size() = ', a2.size())
print('a3.size() = ', a3.size())
print('a4.size() = ', a4.size())
print('a5.size() = ', a5.size())# torch.size() 可以指定特定的子维度数组的维度规模
print()
print('a1.size(0) = ', a1.size(0))
print('a2.size(0) = ', a2.size(0))
print('a3.size(1) = ', a3.size(1))
print('a4.size(1) = ', a4.size(1))
print('a5.size(1) = ', a5.size(1))# JY Lin YDOOK
# torch.shape() 可以指定特定的子维度数组的维度下的具体内容
print()
print('a1.shape[0] = ', a1.shape[0])
print('a2.shape[0] = ', a2.shape[0])
print('a3.shape[0] = ', a3.shape[0])
print('a4.shape[0] = ', a4.shape[0])
print('a5.shape[0] = ', a5.shape[0])print('a3.shape[1] = ', a3.shape[1])
print('a4.shape[1] = ', a4.shape[1])
print('a5.shape[1] = ', a5.shape[1])print('a5.shape[2] = ', a5.shape[2])

输出:

D:\Anaconda\python.exe F:/AI/Pytorch/AI2/A2.py
a1 =  tensor([])
a2 =  tensor([0.])
a3 =  tensor([[0.]])
a4 =  tensor([[0., 0., 0.],[0., 0., 0.]])
a5 =  tensor([[[0., 0., 0., 0., 0.],[0., 0., 0., 0., 0.],[0., 0., 0., 0., 0.]],[[0., 0., 0., 0., 0.],[0., 0., 0., 0., 0.],[0., 0., 0., 0., 0.]]])a1.size() =  torch.Size([0])
a2.size() =  torch.Size([1])
a3.size() =  torch.Size([1, 1])
a4.size() =  torch.Size([2, 3])
a5.size() =  torch.Size([2, 3, 5])a1.size(0) =  0
a2.size(0) =  1
a3.size(1) =  1
a4.size(1) =  3
a5.size(1) =  3a1.shape[0] =  0
a2.shape[0] =  1
a3.shape[0] =  1
a4.shape[0] =  2
a5.shape[0] =  2
a3.shape[1] =  1
a4.shape[1] =  3
a5.shape[1] =  3
a5.shape[2] =  5Process finished with exit code 0



YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别相关推荐

  1. Pytorch中torch.numel(),torch.shape,torch.size()和torch.reshape()函数解析

    一. torch.numel()函数解析 1. 官网链接 torch.numel(),如下图所示: 2. torch.numel()函数解析 torch.numel(input) → int 返回输入 ...

  2. pytorch源码解析2——数据处理torch.utils.data

    迭代器 理解 Python 的迭代器是解读 PyTorch 中 torch.utils.data 模块的关键. 在 Dataset, Sampler 和 DataLoader 这三个类中都会用到 py ...

  3. Pytorch的自定义拓展:torch.nn.Module和torch.autograd.Function

    参考链接:pytorch的自定义拓展之(一)--torch.nn.Module和torch.autograd.Function_LoveMIss-Y的博客-CSDN博客_pytorch自定义backw ...

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

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

  5. pytorch 生成随机数Tensor的方法 torch.rand torch.randn torch.normal torch.linespace

    在使用PyTorch做实验时经常会用到生成随机数Tensor的方法,比如: torch.rand() torch.randn() torch.normal() torch.linespace() 在很 ...

  6. 【Pytorch】torch.Tensor.expand_as()与torch.Tensor.expand()使用与比较

    torch.Tensor.expand_as官方文档地址:https://pytorch.org/docs/stable/generated/torch.Tensor.expand_as.html?h ...

  7. Pytorch中tensor维度和torch.max()函数中dim参数的理解

    Pytorch中tensor维度和torch.max()函数中dim参数的理解 维度 参考了 https://blog.csdn.net/qq_41375609/article/details/106 ...

  8. PyTorch 笔记(05)— Tensor 基本运算(torch.abs、torch.add、torch.clamp、torch.div、torch.mul、torch.pow等)

    1. 函数汇总 Tensor 的基本运算会对 tensor 的每一个元素进行操作,此类操作的输入与输出形状一致,常用操作见下表所示. 对于很多操作,例如 div.mul.pow.fmod.等, PyT ...

  9. PyTorch 笔记(02)— 常用创建 Tensor 方法(torch.Tensor、ones、zeros、eye、arange、linspace、rand、randn、new)

    1. Tensor 概念分类 PyTorch 中的张量(Tensor)类似 NumPy 中的 ndarrays,之所以称之为 Tensor 的另一个原因是它可以运行在 GPU 中,以加速运算. 1.1 ...

最新文章

  1. 32岁被裁,拿N+1,我高兴地失业了
  2. python如何连接自己电脑服务器_Python远程连接windows服务器并上传数据
  3. 730阵列卡支持多大硬盘_730元/瓶的光瓶李渡酒销售过亿后,李渡还有哪些大招?...
  4. 云图说|DRS数据对比——带您随时观测数据一致性
  5. np.array()和np.mat()区别
  6. [hadoop读书笔记] 第五章 MapReduce工作机制
  7. JS_js数组倒序排列、字符串数组转为数字数组,反转数组/字符串/数字
  8. 显示虚拟按钮Menu键
  9. 路由器如何让设置桥接模式
  10. Linux安装Oracle报Checking operating system version must be redhat-3, SuSE-9, redhat-4, UnitedLin
  11. sparkGraphx-航班飞行网图分析
  12. 受害者被锤 法官遭殃 背后的它公关赢了?
  13. 【西语】【3】Tu papa es pirata, o por que eres un tesoro 你爸爸是海盗吗,不然为什么你是个宝藏
  14. 【MD5】快速实现MD5加密解密(盐值)
  15. 正则校验-禁止输入特殊字符和空格
  16. OrgChart-简单实用的组织结构图表jQuery插件
  17. 性能测试数据准备-埋数篇
  18. 小白学习Java第二十六天
  19. [C语言] 在单片机的嵌入式开发中使用宏定义一键开关日志输出/打log调试
  20. 基于Golang的http、web服务框架(SSSS)

热门文章

  1. pt1000和pt100_全面的8pt网格指南
  2. 苹果手表 WatchKit 应用架构简介
  3. 脑与认知神经科学Matlab Psytoolbox认知科学实验设计——视错觉
  4. 算法分析一:基础知识
  5. eSIM卡和SIM卡的区别是什么?
  6. GUI 图片显示(SDL 多媒体开发库)——基于 rt-smart 微内核操作系统
  7. samtools从fastq到bam再到bigwig(bw)
  8. 孤独的灵魂该去何处安家
  9. win7关闭程序兼容性助手和windows Defender
  10. 不管你学的是什么专业,你都应该多少懂些 (来自qq空间)(分享)(转载)