SHARE
TWEET

Untitled

a guest Jun 27th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # sample tensor for us to work with
  2. In [89]: shp = (100, 1024, 14, 14)
  3. In [90]: t = torch.randn(shp)
  4.  
  5. # number of desired repetitions
  6. In [91]: reps = 10
  7.  
  8. # all the magic happens here
  9. # 10 -> we wish to repeat the entries `reps` times along first dimension
  10. # 1 -> we don't want to repeat along the rest of the dimensions
  11. In [92]: rep_tensor = t.repeat(reps, 1, 1, 1).view(-1, *shp[1:])
  12.  
  13. In [93]: rep_tensor.shape
  14. Out[93]: torch.Size([1000, 1024, 14, 14])
  15.      
  16. In [109]: shp = (1, 3, 2)
  17. In [110]: t = torch.randn(shp)
  18.  
  19. In [111]: t
  20. Out[111]:
  21. tensor([[[-0.8974,  0.7790],
  22.          [-0.0637, -1.0532],
  23.          [-0.1682, -0.1921]]])
  24.  
  25. In [112]: rep_tensor = t.repeat(3, 1, 1).view(-1, *shp[1:])
  26.  
  27. In [113]: rep_tensor
  28. Out[113]:
  29. tensor([[[-0.8974,  0.7790],
  30.          [-0.0637, -1.0532],
  31.          [-0.1682, -0.1921]],
  32.  
  33.         [[-0.8974,  0.7790],
  34.          [-0.0637, -1.0532],
  35.          [-0.1682, -0.1921]],
  36.  
  37.         [[-0.8974,  0.7790],
  38.          [-0.0637, -1.0532],
  39.          [-0.1682, -0.1921]]])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top