YDOOK:Pytorch : AI : torch.tensor.size() 与 torch.tensor.shape 的区别
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 的区别相关推荐
- Pytorch中torch.numel(),torch.shape,torch.size()和torch.reshape()函数解析
一. torch.numel()函数解析 1. 官网链接 torch.numel(),如下图所示: 2. torch.numel()函数解析 torch.numel(input) → int 返回输入 ...
- pytorch源码解析2——数据处理torch.utils.data
迭代器 理解 Python 的迭代器是解读 PyTorch 中 torch.utils.data 模块的关键. 在 Dataset, Sampler 和 DataLoader 这三个类中都会用到 py ...
- Pytorch的自定义拓展:torch.nn.Module和torch.autograd.Function
参考链接:pytorch的自定义拓展之(一)--torch.nn.Module和torch.autograd.Function_LoveMIss-Y的博客-CSDN博客_pytorch自定义backw ...
- pytorch(2)Tensor创建和获取tensor的size信息、torch.dtype、torch.device、torch.layout
获取tensor的size信息 >>> import torch >>> from torch.autograd import Variable >>& ...
- pytorch 生成随机数Tensor的方法 torch.rand torch.randn torch.normal torch.linespace
在使用PyTorch做实验时经常会用到生成随机数Tensor的方法,比如: torch.rand() torch.randn() torch.normal() torch.linespace() 在很 ...
- 【Pytorch】torch.Tensor.expand_as()与torch.Tensor.expand()使用与比较
torch.Tensor.expand_as官方文档地址:https://pytorch.org/docs/stable/generated/torch.Tensor.expand_as.html?h ...
- Pytorch中tensor维度和torch.max()函数中dim参数的理解
Pytorch中tensor维度和torch.max()函数中dim参数的理解 维度 参考了 https://blog.csdn.net/qq_41375609/article/details/106 ...
- PyTorch 笔记(05)— Tensor 基本运算(torch.abs、torch.add、torch.clamp、torch.div、torch.mul、torch.pow等)
1. 函数汇总 Tensor 的基本运算会对 tensor 的每一个元素进行操作,此类操作的输入与输出形状一致,常用操作见下表所示. 对于很多操作,例如 div.mul.pow.fmod.等, PyT ...
- PyTorch 笔记(02)— 常用创建 Tensor 方法(torch.Tensor、ones、zeros、eye、arange、linspace、rand、randn、new)
1. Tensor 概念分类 PyTorch 中的张量(Tensor)类似 NumPy 中的 ndarrays,之所以称之为 Tensor 的另一个原因是它可以运行在 GPU 中,以加速运算. 1.1 ...
最新文章
- 32岁被裁,拿N+1,我高兴地失业了
- python如何连接自己电脑服务器_Python远程连接windows服务器并上传数据
- 730阵列卡支持多大硬盘_730元/瓶的光瓶李渡酒销售过亿后,李渡还有哪些大招?...
- 云图说|DRS数据对比——带您随时观测数据一致性
- np.array()和np.mat()区别
- [hadoop读书笔记] 第五章 MapReduce工作机制
- JS_js数组倒序排列、字符串数组转为数字数组,反转数组/字符串/数字
- 显示虚拟按钮Menu键
- 路由器如何让设置桥接模式
- Linux安装Oracle报Checking operating system version must be redhat-3, SuSE-9, redhat-4, UnitedLin
- sparkGraphx-航班飞行网图分析
- 受害者被锤 法官遭殃 背后的它公关赢了?
- 【西语】【3】Tu papa es pirata, o por que eres un tesoro 你爸爸是海盗吗,不然为什么你是个宝藏
- 【MD5】快速实现MD5加密解密(盐值)
- 正则校验-禁止输入特殊字符和空格
- OrgChart-简单实用的组织结构图表jQuery插件
- 性能测试数据准备-埋数篇
- 小白学习Java第二十六天
- [C语言] 在单片机的嵌入式开发中使用宏定义一键开关日志输出/打log调试
- 基于Golang的http、web服务框架(SSSS)