【问题标题】:Is there any way to get torch.mode over multidimensional tensor有没有办法在多维张量上获得 torch.mode
【发布时间】:2021-01-08 02:48:33
【问题描述】:

有什么方法可以在多个维度上应用 torch.mode

例如

import numpy as np
import torch
x = np.random.randint(10, size=(3, 5))
y = torch.tensor(x)

假设你有

[[6 3 7 3 0]
 [2 5 7 9 7]
 [6 1 4 6 3]]

torch.mode 应该返回一个大小为 3 的张量 [3,7,6]

不使用循环

【问题讨论】:

  • 如果你在你的例子中使用torch.mode,你会得到你想要的。你能再举一个例子吗?

标签: python numpy machine-learning pytorch


【解决方案1】:

使用torch中的dimension属性来选择应该使用模式操作符减少哪个维度。

torch.mode(y, dim = 1)[0]

会给你想要的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-10
    • 2017-11-01
    • 2021-01-08
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    相关资源
    最近更新 更多