Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- a = np.arange(12).reshape(3, 4)
- b = a.repeat(2, 0).repeat(2, 1)
- print(b)
- [[ 0 0 1 1 2 2 3 3]
- [ 0 0 1 1 2 2 3 3]
- [ 4 4 5 5 6 6 7 7]
- [ 4 4 5 5 6 6 7 7]
- [ 8 8 9 9 10 10 11 11]
- [ 8 8 9 9 10 10 11 11]]
- >>> a = np.arange(12).reshape(3,4)
- >>> print np.kron(a, np.ones((2,2), dtype=a.dtype))
- [[ 0 0 1 1 2 2 3 3]
- [ 0 0 1 1 2 2 3 3]
- [ 4 4 5 5 6 6 7 7]
- [ 4 4 5 5 6 6 7 7]
- [ 8 8 9 9 10 10 11 11]
- [ 8 8 9 9 10 10 11 11]]
- a = arange(1000000).reshape((1000, 1000)) # dummy data
- from numpy.lib.stride_tricks import as_strided
- N, M = 4,3 # number of time to replicate each point in each dimension
- H, W = a.shape
- 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