You can, of course, take a look at the source for np.kron . It can be found in numpy/lib/shape_base.py and you can see if there are any improvements that can be made or simplifications that can make it more efficient. Alternatively, you can write your own using Cython or some other low-level language bindings to try to achieve better performance.
Or as @matt suggested something like the following, perhaps initially faster:
import numpy as np nrows = 10 a = np.arange(100).reshape(10,10) b = np.tile(a,nrows).reshape(nrows*a.shape[0],-1)
or
b = np.repeat(a,nrows*np.ones(a.shape[0],np.int),axis=0)
Timings:
In [80]: %timeit np.tile(a,nrows).reshape(nrows*a.shape[0],-1) 10000 loops, best of 3: 25.5 us per loop In [81]: %timeit np.kron(a,np.ones((nrows,1))) 10000 loops, best of 3: 117 us per loop In [91]: %timeit np.repeat(a,nrows*np.ones(a.shape[0],np.int),0) 100000 loops, best of 3: 12.8 us per loop
Using np.repeat for size arrays in the example above gives a pretty nice np.repeat speedup that is not too shabby.
source share