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

前端 未结 5 1806
一向
一向 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:23

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

    torch.eq(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.

    UPDATE

    from @deltheil

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

    or even simpler

    torch.all(tens_a.eq(tens_b))
    

提交回复
热议问题