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

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

    You can convert the two tensors to numpy arrays:

    local tens_a = torch.Tensor((9,8,7,6));
    local tens_b = torch.Tensor((9,8,7,6));
    
    a=tens_a.numpy()
    b=tens_b.numpy()
    

    and then something like

    np.sum(a==b)
    4
    

    would give you a fairly good idea of how equals are they.

提交回复
热议问题