pytorch中torch.narrow()函数
torch.narrow(input, dim, start, length) → Tensor
Returns a new tensor that is a narrowed version of input tensor. The dimension dim is input from start to start +length. The returned tensor and input tensor share the same underlying storage.
- Parameters
Example:
>>> x = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> torch.narrow(x, 0, 0, 2)
tensor([[ 1, 2, 3],
[ 4, 5, 6]])
>>> torch.narrow(x, 1, 1, 2)
tensor([[ 2, 3],
[ 5, 6],
[ 8, 9]])
根据定义得知,这个函数是返回tensor的第dim维切片start: start+length的数, 针对例子,
x.size() = (3, 3)
torch.narrow(x, 0, 0, 2) == x[0:0+2, :]
torch.narrow(x, 1, 2, 1) == x[:, 2:2+1]
pytorch中torch.narrow()函数的更多相关文章
- PyTorch 中 torch.matmul() 函数的文档详解
官方文档 torch.matmul() 函数几乎可以用于所有矩阵/向量相乘的情况,其乘法规则视参与乘法的两个张量的维度而定. 关于 PyTorch 中的其他乘法函数可以看这篇博文,有助于下面各种乘法的 ...
- pytorch中torch.unsqueeze()函数与np.expand_dims()
numpy.expand_dims(a, axis) Expand the shape of an array. Insert a new axis that will appear at the a ...
- 交叉熵的数学原理及应用——pytorch中的CrossEntropyLoss()函数
分类问题中,交叉熵函数是比较常用也是比较基础的损失函数,原来就是了解,但一直搞不懂他是怎么来的?为什么交叉熵能够表征真实样本标签和预测概率之间的差值?趁着这次学习把这些概念系统学习了一下. 首先说起交 ...
- Pytorch中torch.autograd ---backward函数的使用方法详细解析,具体例子分析
backward函数 官方定义: torch.autograd.backward(tensors, grad_tensors=None, retain_graph=None, create_graph ...
- pytorch中torch.nn构建神经网络的不同层的含义
主要是参考这里,写的很好PyTorch 入门实战(四)--利用Torch.nn构建卷积神经网络 卷积层nn.Con2d() 常用参数 in_channels:输入通道数 out_channels:输出 ...
- pytorch中的view函数和max函数
一.view函数 代码: a=torch.randn(,,,) b = a.view(,-) print(b.size()) 输出: torch.Size([, ]) 解释: 其中参数-1表示剩下的值 ...
- Pytorch中torch.load()中出现AttributeError: Can't get attribute
原因:保存下来的模型和参数不能在没有类定义时直接使用. Pytorch使用Pickle来处理保存/加载模型,这个问题实际上是Pickle的问题,而不是Pytorch. 解决方法也非常简单,只需显式地导 ...
- PyTorch笔记之 scatter() 函数
scatter() 和 scatter_() 的作用是一样的,只不过 scatter() 不会直接修改原来的 Tensor,而 scatter_() 会 PyTorch 中,一般函数加下划线代表直接在 ...
- Pytorch中randn和rand函数的用法
Pytorch中randn和rand函数的用法 randn torch.randn(*sizes, out=None) → Tensor 返回一个包含了从标准正态分布中抽取的一组随机数的张量 size ...
随机推荐
- SRS之RTMP handshake
1. SrsRtmpServer::handshake 位于 srs_rtmp_stack.cpp. int SrsRtmpServer::handshake() { int ret = ERROR_ ...
- 石川es6课程---18、ES6 复习
石川es6课程---18.ES6 复习 一.总结 一句话总结: 无论在讲课和学习中,复习总结都是很重要 二.ES6 复习 变量 let const 声明方式 能否重复声明 作用域 类型 是否支持变量提 ...
- under the hood
under the hood adjective a metaphorical area that contains the underlying implementation of somethin ...
- leetcode-hard-array-11 Container With Most Water -NO
mycode time limited class Solution(object): def maxArea(self, height): """ :type hei ...
- LC 966. Vowel Spellchecker
Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word ...
- IEDA 实现自动生成序列化号(serialVersionUID)
完整操作流程:Setting->Editor->Inspections->Java->Serialization issues->Serializable class w ...
- 把java项目打包成jar包并可以直接运行【我】
首先创建一个maven的jar项目,然后代码写好后,在项目右键,导出: 选择java下面的可运行的jar文件: 下一步: 要注意的是: launch configuration 此选项是指定选中要导出 ...
- 转:Zepto的使用以及注意事项
为什么选择Zepto.js的原因: zepto.js的语法借鉴并且兼容jQuery,会使用jquery就会使用Zepto.js.Zepto.js是移动端的js库.Zepto.js相当于PC端的jQue ...
- redis的日常操作(1)
一.简介 [概述] redis是一种nosql数据库,他的数据是保存在内存中,同时redis可以定时把内存数据同步到磁盘,即可以将数据持久化,并且他比memcached支持更多的数据结构(string ...
- [NodeJS] 优缺点及适用场景
概述: NodeJS宣称其目标是“旨在提供一种简单的构建可伸缩网络程序的方法”,那么它的出现是为了解决什么问题呢,它有什么优缺点以及它适用于什么场景呢? 本文就个人使用经验对这些问题进行探讨. 一. ...