在火炬中获得元素最小值/最大值

时间:2018-01-28 14:16:55

标签: lua torch tensor

我有2个cuda张量,并希望得到它们之间的最小值。

a=torch.randn(3, 3)
b=torch.randn(3, 3)
c=torch.min(a,b)

无效参数:DoubleTensor DoubleTensor 预期参数:DoubleTensor | [ DoubleTensor ] [ LongTensor ] DoubleTensor索引

现在我想得到一个3乘3的矩阵,其中a和b的最小值(理想情况下也适用于cuda张量)。

任何人都知道如何解决这个问题,我看了看 http://pytorch.org/docs/master/torch.html#torch.max

特别是torch.max(input, other, out=None) → Tensor行 这表明这应该只通过提供两个张量来实现,但如上所述,它会产生错误。

这是在ubuntu 17.04上运行的torch-cl(distro-cl)

1 个答案:

答案 0 :(得分:0)

计算每对值的最大值(最小值)的函数为cmax(分别为cmin)。

尝试

c = torch.cmin(a,b)

有关详细信息,请查看文档https://github.com/torch/torch7/blob/master/doc/maths.md#res-torchcmaxres-tensor1-tensor2

它也适用于CudaTensors。

相关问题