[Numpy-discussion] repmat equivalent
Alex Liberzon
alex.liberzon at gmail.com
Thu Feb 23 15:46:08 EST 2006
I am also mostly Matlab user and I like repmat() a lot. I just
realized that in SciPy, i am confused about NumPy/SciPy, but it is
possible in both :-)) it is much, much easier. Just use r_[a,a] and
c_[a,a] and you get a concatination like repmat() does. if you need
'm' times row concatenation of matrix, you can use (sorry for the ugly
way, Pythoners):
eval('r_['+m*'a,'+']')
then, the repmat is just: (qute, isn't it)
def repmat(a,m,n):
from scipy import r_, c_
a = eval('r_['+m*'a,'+']')
return eval('c_['+n*'a,'+']')
the test is:
>>> from scipy import *
numerix Numeric 24.2
>>> a = array([[0,1],[2,3]])
>>> a
array([[0, 1],
[2, 3]])
>>> repmat(a,2,3)
array([[0, 1, 0, 1, 0, 1],
[2, 3, 2, 3, 2, 3],
[0, 1, 0, 1, 0, 1],
[2, 3, 2, 3, 2, 3]])
Best,
Alex Liberzon <alex.liberzonNOSPAMFORMEPLEASE at gmail.com>
More information about the NumPy-Discussion
mailing list