Compare Number of Equal Elements in Tensors
I have two tensors of dimension 1000 * 1. I want to check how many of the 1000 elements are equal in the two tensors. I think I should be able to do this in one line like Numpy but couldn't find a similar function. 

You can just use the == operator to check for equality and then sum the resulting tensor:

# Import torch and create dummy tensors
&gt;&gt;&gt; import torch
&gt;&gt;&gt; A = torch.randint(2, (10,))
&gt;&gt;&gt; A
tensor([0, 0, 0, 1, 0, 1, 0, 0, 1, 1])
&gt;&gt;&gt; B = torch.randint(2, (10,))
&gt;&gt;&gt; B
tensor([0, 1, 1, 0, 1, 0, 0, 1, 1, 0])

# Checking for number of equal values
&gt;&gt;&gt; (A == B).sum()
tensor(3)




Edit:

torch.eq yields to the same result. So if you for some reason prefer that:

&gt;&gt;&gt; torch.eq(A, B).sum()
tensor(3)

