Guest User

Untitled

a guest
Dec 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. torch_tensor.shuffle(order)
  2.  
  3. import torch
  4. import numpy as np
  5.  
  6. t = torch.rand(10)
  7. print('Original Tensor:', t)
  8.  
  9. order = np.array(range(10))
  10. np.random.shuffle(order)
  11. print('Order:', order)
  12.  
  13. # in-place changing of values
  14. t[np.array(range(10))] = t[order]
  15. print('New Tensor:', t)
  16.  
  17. Original Tensor: tensor([ 0.3380, 0.3450, 0.2253, 0.0279, 0.3945, 0.6055, 0.1489,
  18. 0.7676, 0.4213, 0.2683])
  19. Order: [7 1 3 6 2 9 0 5 4 8]
  20. New Tensor: tensor([ 0.7676, 0.3450, 0.0279, 0.1489, 0.2253, 0.2683, 0.3380,
  21. 0.6055, 0.3945, 0.4213])
Add Comment
Please, Sign In to add comment