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 ...
随机推荐
- 2 大O表示法
1.大O表示法 表示程序的执行时间或占用空间随数据规模的增长趋势. 算法操作 时间复杂度 线性查找 O(n) 二分查找 O(logn) 无序数组插入 O(1) 无序数组删除 O(n) 有序数组插入 O ...
- HashMap三两事
前言 JDK8中对HashMap做了优化,依然是用数组存储数据,但是扩容时采用双链表的方式避免了高并发情况下导致出现循环链表的问题,另外也引入了红黑树,提高碰撞元素的搜索速度. 一段代码 下面这段代码 ...
- android data binding jetpack I 环境配置 model-view 简单绑定
android data binding jetpack VIII BindingConversion android data binding jetpack VII @BindingAdapter ...
- phpStrom破解 + Your license has expired
找到 C:\Windows\System32\drivers\etc 的 hosts文件在最后加上"0.0.0.0 account.jetbrains.com" 然后点击获取注册码 ...
- LC 660. Remove 9 【lock, hard】
Start from integer 1, remove any integer that contains 9 such as 9, 19, 29... So now, you will have ...
- GitHub-Microsoft:DotNet
ylbtech-GitHub-Microsoft:DotNet 1.返回顶部 · · wcf This repo contains the client-oriented WCF libraries ...
- javascript之Screen(屏幕)对象
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [shell]上一个命令执行完成,才执行下一个操作 | shell脚本中判断上一个命令是否执行成功
shell脚本中判断上一个命令是否执行成功 shell中使用符号“$?”来显示上一条命令执行的返回值,如果为0则代表执行成功,其他表示失败.结合if-else语句实现判断上一个命令是否执行成功. 场 ...
- linux添加用户所在群组
etc目录下面有两个文件一个passwd一个grouppasswd里gid是主组,其他组是扩展组,扩展组在/etc/group里描述.useradd username如果不指定,默认创建一个与uid相 ...
- WPF 键盘全局接收消息
1.========================================================================== 在c#中怎样禁用鼠标左键的使用,其实我们可以通 ...