Skip to content

Instantly share code, notes, and snippets.

@MLWhiz
Created September 7, 2020 14:33
Show Gist options
  • Save MLWhiz/68b77e357a97733189f1c5d0d51536b0 to your computer and use it in GitHub Desktop.
Save MLWhiz/68b77e357a97733189f1c5d0d51536b0 to your computer and use it in GitHub Desktop.
A = torch.randn(3,4)
W = torch.randn(4,2)
# Multiply Matrix A and W
t = A.mm(W)
print(f"Created Tensor t by Multiplying A and W:\n{t}")
# Transpose Tensor t
t = t.t()
print(f"Transpose of Tensor t:\n{t}")
# Square each element of t
t = t**2
print(f"Square each element of Tensor t:\n{t}")
# return the size of a tensor
print(f"Size of Tensor t using .size():\n{t.size()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment