【问题标题】:torch extract sub tensor using indices火炬使用索引提取子张量
【发布时间】:2016-06-27 06:39:31
【问题描述】:

我想从原始张量中提取一个子张量,其中包含另一个张量定义的索引处的元素。

th> ls = torch.linspace(1, 10, 10)
                                                                      [0.0001s]
th> ls
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
[torch.DoubleTensor of size 10]
                                                                      [0.0002s]
th> i = torch.FloatTensor(3)
                                                                      [0.0001s]
th> i[1] = 2
                                                                      [0.0000s]
th> i[2] = 7
                                                                      [0.0000s]
th> i[3] = 9
                                                                      [0.0000s]
th> ls.eq(i)
[string "_RESULT={ls.eq(i)}"]:1: invalid arguments: FloatTensor
expected arguments: [*ByteTensor*] DoubleTensor double | *DoubleTensor* DoubleTensor double | [*ByteTensor*] DoubleTensor DoubleTensor | *DoubleTensor* DoubleTensor DoubleTensor
stack traceback:
        [C]: in function 'eq'
        [string "_RESULT={ls.eq(i)}"]:1: in main chunk
        [C]: in function 'xpcall'
        /home/ubuntu/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
        ...untu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
        [C]: at 0x00406670
                                                                      [0.0001s]
th>

如何使用 i 中的索引查询 ls?

【问题讨论】:

    标签: lua deep-learning torch


    【解决方案1】:
    sub = ls:index(1, torch.LongTensor{2, 7, 9})
    

    [Tensor] index(dim, index)

    【讨论】:

      猜你喜欢
      • 2022-10-23
      • 2016-07-20
      • 1970-01-01
      • 2020-08-02
      • 2022-07-20
      • 2021-06-18
      • 2020-10-26
      • 2020-11-24
      • 2021-07-08
      相关资源
      最近更新 更多