Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import torch
  2. import torch.nn.utils.rnn as rnn_utils
  3.  
  4. a = torch.tensor([[1,2],[2,2],[3,3],[3,2],[3,2]])
  5. b = torch.tensor([[4,2],[5,1],[4,4]])
  6. c = torch.tensor([[6,9]])
  7. result = rnn_utils.pad_sequence([a, b, c])
  8.  
  9. tensor([[[1, 2],
  10. [4, 2],
  11. [6, 9]],
  12.  
  13. [[2, 2],
  14. [5, 1],
  15. [0, 0]],
  16.  
  17. [[3, 3],
  18. [4, 4],
  19. [0, 0]],
  20.  
  21. [[3, 2],
  22. [0, 0],
  23. [0, 0]],
  24.  
  25. [[3, 2],
  26. [0, 0],
  27. [0, 0]]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement