Tensor #842
balakrish181
started this conversation in
General
Tensor
#842
Replies: 1 comment
-
PyTorch Implementationimport torch
# scalar
scalar = torch.tensor(7)
print(scalar, scalar.ndim, scalar.shape, sep=',')
# vector
vector = torch.tensor([7, 4])
print(vector, vector.ndim, vector.shape, sep=',')
# matrix
MATRIX = torch.tensor([[7, 10],
[4, 3],
[5, 1]])
print(MATRIX, MATRIX.ndim, MATRIX.shape, sep=',')
# tensor
TENSOR = torch.tensor([[[[7, 4], [0, 1]],
[[1, 9], [2, 3]],
[[5, 6], [8, 8]]]])
print(TENSOR, TENSOR.ndim, TENSOR.shape, sep=',') Outputtensor(7),0,torch.Size([])
tensor([7, 4]),1,torch.Size([2])
tensor([[ 7, 10],
[ 4, 3],
[ 5, 1]]),2,torch.Size([3, 2])
tensor([[[[7, 4],
[0, 1]],
[[1, 9],
[2, 3]],
[[5, 6],
[8, 8]]]]),4,torch.Size([1, 3, 2, 2]) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to know how to replicate Tensor in this image in code.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions