Skip to content

I am not understand this line #238

Answered by AlienSarlak
ammarsaf asked this question in Q&A
Discussion options

You must be logged in to vote

Is your question still unanswered? If not have a look at the below example it might help:

This part makes two random boolean list of size 10 each:

import torch
torch.manual_seed(SEED)
X = torch.randint(0, 2, (10,))
Y = torch.randint(0, 2, (10,))


Output: 
```python
(tensor([0, 1, 0, 1, 1, 1, 1, 0, 1, 1])
 tensor([0, 1, 1, 0, 1, 1, 1, 1, 1, 1]))

Then by the following line we actually count the indices where two arrays have the same value:

sum = (X == Y).sum()

The output is look like:

tensor(7) 

And to get the value itself:

sum = sum.item()

Output:

7.0

Which means that 7 entries in the arrays have the same values:

[**0**, **1**, 0, 1, **1**, **1**, **1**, 0, **1**, **1**]
[**0**, **1**, 1,…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@ammarsaf
Comment options

@AlienSarlak
Comment options

Comment options

You must be logged in to vote
1 reply
@mrdbourke
Comment options

Answer selected by mrdbourke
Comment options

You must be logged in to vote
1 reply
@ammarsaf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants