New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.size() vs .shape, which one should be used? #5544
Comments
Hi, |
Yes, |
Thank you. |
FWIW this redundancy has always bugged me. For some reason |
what about |
That |
.size() method returns total elements in a dataframe , for eg shape of a tensor might be (10,3) , here total elements in tensor would be returned by .size() = 10X3 = 30 elements!! |
@Risingabhi Nope, that's not how it works in PyTorch: |
yes, that's the case in pytorch |
That's what |
If you're like me and looking to pick one or the other, some common use cases compared: t = torch.arange(60).view(3, 4, 5)
t.shape == t.size() # just get the size/shape
t.shape[1] == t.size(1) # get one element from the size/shape
t.shape[1:] == t.size()[1:] # get several elements from the size/shape To my eyes, |
|
Is there any difference in behavior for |
Summary: Add `Tensor.Shape` doc. Ref: - pytorch#5544 - pytorch#1980 Differential Revision: D47278630 fbshipit-source-id: 823ee4776a8ef1086c3b37c3d1af3b5bb9355a1c
Summary: Pull Request resolved: pytorch#104750 Add `Tensor.Shape` doc. Ref: - pytorch#5544 - pytorch#1980 Differential Revision: D47278630 fbshipit-source-id: b549a68eb632f46db921fd5ae89ad58767a880a4
Summary: Pull Request resolved: pytorch#104750 Add `Tensor.Shape` doc. Ref: - pytorch#5544 - pytorch#1980 Differential Revision: D47278630 fbshipit-source-id: aa2466cba60b21860338e1ea6b8850f4395b6255
Summary: Add `Tensor.Shape` doc. Fix: #104038 Ref: - #5544 - #1980 Differential Revision: D47278630 CC: @svekars @carljparker Pull Request resolved: #104750 Approved by: https://github.com/mikaylagawarecki
Hi,
This is not an issue per se, but more of a question of best practices. I notice that there a shape attribute and a size function that both return the size/shape of a tensor. I also notice that .shape is not documented, but according to various release notes, Pytorch tries to be as close as possible to numpy. So, knowing this, is .shape really supported or just an undocumented functionality that could disappear in the next version?
Thank you.
The text was updated successfully, but these errors were encountered: