From: Albert S. <fu...@gm...> - 2006-02-23 21:22:14
|
Hello On 2/23/06, Travis Oliphant <oli...@ie...> 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 rep= mat: from numpy import asarray from scipy.linalg import kron def repmat(a, m, n): a =3D asarray(a) return kron(ones((m, n)), a) This test: a =3D repmat(1, 1, 1) assert_equal(a, 1) fails with: ValueError: 0-d arrays can't be concatenated and this test: a =3D 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 |