How to check if two Torch tensors or matrices are equal?

前端 未结 5 1799
一向
一向 2021-02-04 23:50

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

For example:

local tens_a = torc         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 00:32

    Try this if you want to ignore small precision differences which are common for floats

    torch.all(torch.lt(torch.abs(torch.add(tens_a, -tens_b)), 1e-12))
    

提交回复
热议问题