【问题标题】:torch.Tensor manipulation - call methods on sub vectorstorch.Tensor 操作 - 在子向量上调用方法
【发布时间】:2016-02-25 15:28:52
【问题描述】:

我有一个张量,它是一个包含 9 个单元的向量,我想像在 Matlab 中一样将单元 3 到 6 拉出来而不循环。

更多信息:

th> my_table = {0.1, 0.2, 0.3, ... 0.9}
-- I create tensor out of it.
th> t_table = torch.Tensor(my_table )
-- I get the vector 0.1, 0.2, 0.3, ..., 0.9
-- Now I will get it's mean like this:
th> torch.mean(t_table)
0.5
-- Now I would like to do for example torch.mean on cells 3-6.
th> --<what to write here?>

【问题讨论】:

    标签: lua lua-table torch


    【解决方案1】:

    我没有使用 torch 库的经验,但 torch.Tensor 的文档显示存在 :sub:select 元方法以及非常棒的 __index 方法,它支持对张量。

    您可以使用其中之一来获取索引 3 到 6 的张量并在其上应用 torch.mean

    【讨论】:

      猜你喜欢
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      • 1970-01-01
      • 2017-04-30
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多