Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import numpy as np
  2.  
  3. a = np.arange(12).reshape(3, 4)
  4. b = a.repeat(2, 0).repeat(2, 1)
  5. print(b)
  6.  
  7. [[ 0 0 1 1 2 2 3 3]
  8. [ 0 0 1 1 2 2 3 3]
  9. [ 4 4 5 5 6 6 7 7]
  10. [ 4 4 5 5 6 6 7 7]
  11. [ 8 8 9 9 10 10 11 11]
  12. [ 8 8 9 9 10 10 11 11]]
  13.  
  14. >>> a = np.arange(12).reshape(3,4)
  15. >>> print np.kron(a, np.ones((2,2), dtype=a.dtype))
  16. [[ 0 0 1 1 2 2 3 3]
  17. [ 0 0 1 1 2 2 3 3]
  18. [ 4 4 5 5 6 6 7 7]
  19. [ 4 4 5 5 6 6 7 7]
  20. [ 8 8 9 9 10 10 11 11]
  21. [ 8 8 9 9 10 10 11 11]]
  22.  
  23. a = arange(1000000).reshape((1000, 1000)) # dummy data
  24.  
  25. from numpy.lib.stride_tricks import as_strided
  26. N, M = 4,3 # number of time to replicate each point in each dimension
  27. H, W = a.shape
  28. b = as_strided(a, (H, N, W, M), (a.strides[0], 0, a.strides[1], 0)).reshape((H*N, W*M))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement