【问题标题】:Lua/torch multiplication of 1D and 2D tensors1D 和 2D 张量的 Lua/torch 乘法
【发布时间】:2016-10-06 13:15:53
【问题描述】:

我正在尝试在 lua 中将两个矩阵相乘,其尺寸为 a=40,000x1 和 b=1x40,000。在 Lua 中,40,000x1 矩阵显示为一维张量,而 1x40,000 矩阵显示为二维张量。每当我尝试简单地使用 a*b 将它们相乘时,就会出现错误:multiplication between 1D and 2D tensors not yet supported。我不能迭代地遍历每个索引,因为这个函数在我的程序中经常使用,并且会大大增加执行时间。如何将ab 相乘?

【问题讨论】:

    标签: matrix lua torch


    【解决方案1】:

    使用view:

    c = a:view(40000, 1) * b
    

    【讨论】:

    • 错误:expecting a contiguous tensor stack traceback.
    • a:contiguous():view(40000, 1) * b(注意:这里涉及到内存拷贝)
    猜你喜欢
    • 2016-10-27
    • 2021-10-07
    • 2016-07-02
    • 2016-01-12
    • 1970-01-01
    • 2021-06-17
    • 2021-01-28
    • 2019-06-24
    • 1970-01-01
    相关资源
    最近更新 更多