【问题标题】:How to expand dims in Torch (add dimension to tensor)如何在 Torch 中扩展暗淡(向张量添加维度)
【发布时间】:2016-11-29 09:37:11
【问题描述】:

我想为张量添加维度,如numpy.expand_dims。我该怎么做?

我可以使用以下代码:

a = torch.Tensor({{1,2}, {3,4}, {5,6}}) --array with shape (3,2)
a_size_table = a:size():totable()
table.insert(a_size_table, 1, 1)  -- adding `1` before first dimension
a:reshape(torch.LongStorage(a_size_table)) -- returning array with shape (1,3,2)

这对我来说似乎太复杂了(比较一下np.expand_dims(a,0))。可能有更好的方法吗?

【问题讨论】:

    标签: lua torch


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-08
      • 2017-09-22
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      相关资源
      最近更新 更多