torch.Tensor

torch.Tensor

Creator
Creator
Seonglae Cho
Created
Created
2019 Dec 15 8:27
Editor
Edited
Edited
2024 Nov 10 11:51
Refs
Refs
Tensor
(batch_size, width, height), (batch_size, dim)
  • usually 1D is bias
  • usually 2D is weight matrix
  • usually 3D is sequential or image/video data
# One way tensor = torch.ones([100, 2]).cuda() # Better Code to Create Tensors Directly on GPU tensor = torch.ones([100, 2], device="cuda:0")
Pytorch Tensor member functions
 
torch.Tensor members
 
 
Pytorch Tensors
 
 
 

numpy index manipulation

  • […, None] append last dimension
  • [None, …] insert first dimension

Indexing for In-place operations to save memory (
numpy Boolean Indexing
)

x = torch.randn(100, 100, 100) # Large tensor with random values x[x < 0] += 0.1 # Use advanced indexing to update the negative values
 
 
 
 
 
 

Recommendations