当前位置:网站首页>Gather function in pytorch_
Gather function in pytorch_
2022-06-12 20:58:00 【Human high quality Algorithm Engineer】
Let's first look at the explanation of the official documents :
Gathers values along an axis specified by dim.
For a 3-D tensor the output is specified by:
out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0
out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1
out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2
If input is an n-dimensional tensor with size (x0,x1…,xi−1,xi,xi+1,…,xn−1)(x_0, x_1…, x_{i-1}, x_i, x_{i+1}, …, x_{n-1})(x0,x1…,xi−1,xi,xi+1,…,xn−1) and dim = i, then index must be an nnn -dimensional tensor with size (x0,x1,…,xi−1,y,xi+1,…,xn−1)(x_0, x_1, …, x_{i-1}, y, x_{i+1}, …, x_{n-1})(x0,x1,…,xi−1,y,xi+1,…,xn−1) where y≥1y \geq 1y≥1 and out will have the same size as index.
Let's take an example :
import torch
b = torch.Tensor([[1, 2, 3], [4, 5, 6]])
index_1 = torch.LongTensor([[0, 1], [2, 0]])
print(torch.gather(b, dim=1, index=index_1))
Output
tensor([[1., 2.],
[6., 4.]])
Next, calculate the output of the result according to the document ,out[0][0] = input[0][index[0][0]] = input[0][0] = 1
out[0][1] = input[0][index[0][1]] = input[0][1] = 2
out[1][0] = input[1][index[1][0]] = input[1][2] = 6
out[1][1] = input[1][index[1][1]] = input[1][0] = 4
Reprinted from :https://blog.csdn.net/weixin_39757893/article/details/112926469
边栏推荐
- Properties to YML
- 多机房动环状态网络触摸屏监控解决方案
- The required books for software testers (with e-books) recommended by senior Ali have benefited me a lot
- Restful API 接口规范
- Data visualization - broken line area chart
- Large and small end conversion
- New product release Junda intelligent integrated environmental monitoring terminal
- Deploy etcd cluster in static pod mode
- Research Report on hydraulic injection machine industry - market status analysis and development prospect forecast
- 跳槽前恶补面试题,金三成功上岸腾讯,拿到30k的测开offer
猜你喜欢

EditText control starts from the upper left corner

字符串基础知识

QT pro file configuration ffmpeg macro

View 的事件分发机制

Design and practice of Hudi bucket index in byte skipping

Leetcode: 210. Programme II

解决cvxpy报错The solver GLPK_MI is not installed

Successful transition from self-study test halfway, 10K for the first test

Before job hopping, Jin San made up the interview questions. Jin San successfully landed at Tencent and got a 30K test offer

Data visualization - histogram
随机推荐
The year of the outbreak of financial innovation! All dtinsight products of kangaroo cloud data stack have passed the special test of Xinchuang of ICT Institute
JS深浅拷贝
new做了哪几件事
shell语言
测试人如何规划自己的未来?才能实现入行2年达到25k?
Data visualization - broken line area chart
解决cvxpy报错The solver GLPK_MI is not installed
跳槽前恶补面试题,金三成功上岸腾讯,拿到30k的测开offer
循环插入excel某一列,以及多列之和
作用域和作用域链
Event distribution mechanism of view
Market trend report, technical innovation and market forecast of hydraulic torque wrench in China
How to download putty using alicloud image?
Proxy and reflection
JSP中的监听器
Data visualization - biaxial comparison effect
China hydraulic cylinder linear position sensor market trend report, technical dynamic innovation and market forecast
InRelease: 由于没有公钥,无法验证下列签名: NO_PUBKEY EB3E94ADBE1229CF
UVa11991 Easy Problem from Rujia Liu
Market trend report, technical innovation and market forecast of hydraulic chain hoist in China