[Numpy-discussion] repmat equivalent?
Albert Strasheim
fullung at gmail.com
Thu Feb 23 13:23:01 CST 2006
Hello
On 2/23/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> Albert Strasheim wrote:
>
> >Hello all
> >
> >I recently started using NumPy and one function that I am really
> >missing from MATLAB/Octave is repmat. This function is very useful for
> >implementing algorithms as matrix multiplications instead of for
> >loops.
> >
> >
> There is a function in scipy.linalg called kron that could be brought
> over which can do a repmat.
I quickly tried a few of my test cases with following implementation of repmat:
from numpy import asarray
from scipy.linalg import kron
def repmat(a, m, n):
a = asarray(a)
return kron(ones((m, n)), a)
This test:
a = repmat(1, 1, 1)
assert_equal(a, 1)
fails with:
ValueError: 0-d arrays can't be concatenated
and this test:
a = repmat(array([1,2]), 2, 3)
assert_array_equal(a, array([[1,2,1,2,1,2], [1,2,1,2,1,2]]))
fails with:
AssertionError: Arrays are not equal (shapes (12,), (2, 6) mismatch)
Regards
Albert
More information about the Numpy-discussion
mailing list