Why is the repmat
function from numpy.matlib
so much faster than numpy.kron
(i.e., Kronecker Product) to repeat blocks of matrices?
A MWE would be:
test_N = 1000
test_vec = np.random.rand(test_N, 2)
rep_vec = np.matlib.repmat(test_vec, 100, 1)
kron_vec = kron(ones((100,1)), test_vec)
%%timeit
rep_vec = np.matlib.repmat(test_vec, 10, 1)
53.5 µs ± 2.42 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%%timeit
kron_vec = kron(test_vec, ones((10,1)))
1.65 ms ± 228 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
Some of my own timings:
Your
looks more like a
ones((100,1))
time test.Mine is longer than others, but not as drastically so.
A similar multiplication approach (like the
outer
ofkron
, but no need for theconcatenate
step):repmat
:Using
tile
instead:and
repeat
directly: