[Numpy-discussion] repmat equivalent?

Stefan van der Walt stefan at sun.ac.za
Fri Feb 24 00:13:01 CST 2006


On Thu, Feb 23, 2006 at 11:21:39PM +0200, Albert Strasheim wrote:
> > Thus,
> >
> > kron(ones((2,3)), arr)
> >
> >  >>> sl.kron(ones((2,3)),arr)
> > array([[1, 2, 1, 2, 1, 2],
> >        [3, 4, 3, 4, 3, 4],
> >        [1, 2, 1, 2, 1, 2],
> >        [3, 4, 3, 4, 3, 4]])
> >
> > gives you the equivalent of
> >
> > repmat(arr, 2,3)
> 
> Thanks! Merging this into numpy would be much appreciated. Stefan van
> der Walt did some benchmarks and this approach seems faster than
> anything we managed for 2D arrays.

My benchmark was wrong -- this function is not as fast as the version
Albert previously proposed.  Below follows the benchmark of seven
possible repmat functions:

---------------------------------------------------------------------------
0 : 1.09316706657 (Albert)
1 : 6.15612506866 (Stefan)
2 : 5.21671295166 (Stefan)
3 : 2.78160500526 (Stefan)
4 : 1.20426011086 (Albert Optimised)
5 : 11.0923781395 (Travis)
6 : 3.47499799728 (Alex)
---------------------------------------------------------------------------
0 : 1.17543005943
1 : 6.03165698051
2 : 5.7597899437
3 : 2.40381717682
4 : 1.09497308731
5 : 11.6657807827
6 : 7.11567497253
---------------------------------------------------------------------------
0 : 2.03999996185
1 : 9.87535595894
2 : 8.86893296242
3 : 4.56993699074
4 : 2.02298903465
5 : 22.8858327866
6 : 10.7882151604
---------------------------------------------------------------------------

I attach the code.

Stéfan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: repmat.py
Type: text/x-python
Size: 1437 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060224/1bdd9918/attachment.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: repmat_bench.py
Type: text/x-python
Size: 682 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060224/1bdd9918/attachment-0001.py 


More information about the Numpy-discussion mailing list