码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Pytorch - scatter_()


    1. torch_scatter.scatter(src: Tensor, index: Tensor, dim: int = - 1,
    2. out: Optional[Tensor] = None,
    3. dim_size: Optional[int] = None,
    4. reduce: str = 'sum')→ Tensor
    • src – The source tensor. ( 源张量)

    • index – The indices of elements to scatter.(要分散的元素的索引)

    • dim – The axis along which to index. (default: -1) (要索引的轴(默认值:-1))

    • out – The destination tensor. (目标张量)

    • dim_size – If out is not given, automatically create output with size dim_size at dimension dim. If dim_size is not given, a minimal sized output tensor according to index.max() + 1 is returned.(如果未给出out,则在 dim 处自动创建尺寸为 dim_size 的输出。如果没有给出 dim_size,则返回根据 index.max() + 1 的最小尺寸输出张量);

    • reduce – The reduce operation ("sum", "mul", "mean", "min" or "max"). (default: "sum") (reduce 操作(“ sum”、“ mul”、“ mean”、“ min”或“ max”);

    直观的理解:

    对于三维矩阵:

    1. y = y.scatter(dim,index,src)
    2. #则结果为:
    3. y[ index[i][j][k] ] [j][k] = src[i][j][k] # if dim == 0
    4. y[i] [ index[i][j][k] ] [k] = src[i][j][k] # if dim == 1
    5. y[i][j] [ index[i][j][k] ] = src[i][j][k] # if dim == 2

    对于二维矩阵:

    1. y = y.scatter(dim,index,src)
    2. #则:
    3. y [ index[i][j] ] [j] = src[i][j] #if dim==0
    4. y[i] [ index[i][j] ] = src[i][j] #if dim==1

    ps: index的维度,必须和src维度相同;

    举例:

    1. >>> src = torch.randn(3, 3)
    2. >>> src
    3. tensor([[-1.8801, 0.9740, 1.2865],
    4. [ 0.3140, 1.2396, -1.3452],
    5. [-0.8937, 0.6916, -2.0134]])
    6. >>> y = y.scatter_(0,index,src)
    7. >>> index = torch.tensor([[0, 1, 0],[1,0,1],[2,1,0]])
    8. >>> index
    9. tensor([[0, 1, 0],
    10. [1, 0, 1],
    11. [2, 1, 0]])
    12. >>> y = y.scatter_(0,index,src)
    13. >>> y
    14. tensor([[-1.8801, 1.2396, -2.0134],
    15. [ 0.3140, 0.6916, -1.3452],
    16. [-0.8937, 0.0000, 0.0000],
    17. [ 0.0000, 0.0000, 0.0000]])

  • 相关阅读:
    高压MOS管1000V/2A 可代替IXFP4N100 数据表(PDF)
    YOLO V5、SAM、RESNET50模型在GPU环境下搭建过程
    springboot中Configuration注解和Component注解功能的区别和联系?
    数据挖掘 分类方法
    【PostgreSQL】主键添加自增
    【LeetCode高频SQL50题-基础版】打卡第8天:第41~45题
    对于电商API接口详情问题-淘宝/天猫的介绍
    华清远见(上海中心)22071
    线性表顺序表综合应用题P18
    Spring Boot开发之SpringSercurity(续)
  • 原文地址:https://blog.csdn.net/qq_40671063/article/details/126256756
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号