Replies: 1 comment 2 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I was trying out indexing a tensor and to my surprise, I found indexing returns different results depending on whether I use a single square bracket (with comma separated indices) OR multiple square brackets (with each index having it's own bracket). Here's my code:-
`import torch
tensorA = torch.arange(1,19).reshape(2,3,3)
print(tensorA)
print(tensorA[0][:][2])
print("\n")
x = torch.arange(1,19).reshape(2,3,3)
print(x)
print(x[0,:,2])`
This is what the output is:-
tensor([[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]],
tensor([7, 8, 9])
tensor([[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]],
tensor([3, 6, 9])
My intention is to get the second outcome but I'm not able to understand why the first one is returning tensor([7, 8, 9])
I'm very new to this, would really appreciate if anyone can guide. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions