如何检查两个Torch张量或矩阵是否相等? [英] How to check if two Torch tensors or matrices are equal?

查看:2073
本文介绍了如何检查两个Torch张量或矩阵是否相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Torch命令,该命令检查两个张量是否具有相同的内容,如果它们具有相同的内容,则返回TRUE.

I need a Torch command that checks if two tensors have the same content, and returns TRUE if they have the same content.

例如:

local tens_a = torch.Tensor({9,8,7,6});
local tens_b = torch.Tensor({9,8,7,6});

if (tens_a EQUIVALENCE_COMMAND tens_b) then ... end

在此脚本中,我应该使用什么代替EQUIVALENCE_COMMAND?

What should I use in this script instead of EQUIVALENCE_COMMAND ?

我只是用==尝试过,但是它不起作用.

I tried simply with == but it does not work.

推荐答案

https://github.com/torch/torch7/blob/master/doc/maths.md#torcheqa-b

torch.eq(a, b)

Implements ==运算符将a中的每个元素与b(如果b是一个数字)或a中的每个元素与b中的对应元素进行比较.

Implements == operator comparing each element in a with b (if b is a number) or each element in a with corresponding element in b.

来自@deltheil

from @deltheil

torch.all(torch.eq(tens_a, tens_b))

或更简单

torch.all(tens_a.eq(tens_b))

这篇关于如何检查两个Torch张量或矩阵是否相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆