build numpy matrix out of smaller matrix
Hi, is there any possibility to define a numpy matrix, via a smaller given matrix, i.e. in matlab i can do this like a=[1 2 ; 3 4 ] A=[a a ; a a ] so that i finally get A=[ [1,2,1,2] [3,4,3,4] [1,2,1,2] [3,4,3,4]] i tried different things on numpy which didn't work any ideas ? thank you -- View this message in context: http://old.nabble.com/build-numpy-matrix-out-of-smaller-matrix-tp32896004p32... Sent from the Numpy-discussion mailing list archive at Nabble.com.
On Thu, Dec 1, 2011 at 10:52 AM, jonasr <jonas.ruebsam@web.de> wrote:
Hi, is there any possibility to define a numpy matrix, via a smaller given matrix, i.e. in matlab i can do this like
a=[1 2 ; 3 4 ]
A=[a a ; a a ]
so that i finally get
A=[ [1,2,1,2] [3,4,3,4] [1,2,1,2] [3,4,3,4]]
i tried different things on numpy which didn't work any ideas ?
thank you
numpy.tile() might be what you are looking for. Cheers! Ben Root
On Thu, Dec 1, 2011 at 12:26 PM, Benjamin Root <ben.root@ou.edu> wrote:
On Thu, Dec 1, 2011 at 10:52 AM, jonasr <jonas.ruebsam@web.de> wrote:
Hi, is there any possibility to define a numpy matrix, via a smaller given matrix, i.e. in matlab i can do this like
a=[1 2 ; 3 4 ]
A=[a a ; a a ]
so that i finally get
A=[ [1,2,1,2] [3,4,3,4] [1,2,1,2] [3,4,3,4]]
i tried different things on numpy which didn't work any ideas ?
thank you
numpy.tile() might be what you are looking for.
or which is my favorite tile and repeat replacement
a= np.array([[1, 2], [3, 4]]) np.kron(np.ones((2,2)), a) array([[ 1., 2., 1., 2.], [ 3., 4., 3., 4.], [ 1., 2., 1., 2.], [ 3., 4., 3., 4.]])
np.kron(a, np.ones((2,2))) array([[ 1., 1., 2., 2.], [ 1., 1., 2., 2.], [ 3., 3., 4., 4.], [ 3., 3., 4., 4.]])
Josef
Cheers! Ben Root
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Oops, slightly incorrect answer, but anyway my intention was more along the lines: In []: a= np.array([[1, 2], [3, 4]]) In []: np.c_[[a, a], [a, a]].reshape(4, 4) Out[]: array([[1, 2, 1, 2], [3, 4, 3, 4], [1, 2, 1, 2], [3, 4, 3, 4]]) On Thu, Dec 1, 2011 at 8:16 PM, <josef.pktd@gmail.com> wrote:
On Thu, Dec 1, 2011 at 12:26 PM, Benjamin Root <ben.root@ou.edu> wrote:
On Thu, Dec 1, 2011 at 10:52 AM, jonasr <jonas.ruebsam@web.de> wrote:
Hi, is there any possibility to define a numpy matrix, via a smaller given matrix, i.e. in matlab i can do this like
a=[1 2 ; 3 4 ]
A=[a a ; a a ]
so that i finally get
A=[ [1,2,1,2] [3,4,3,4] [1,2,1,2] [3,4,3,4]]
i tried different things on numpy which didn't work any ideas ?
thank you
numpy.tile() might be what you are looking for.
or which is my favorite tile and repeat replacement
a= np.array([[1, 2], [3, 4]]) np.kron(np.ones((2,2)), a) array([[ 1., 2., 1., 2.], [ 3., 4., 3., 4.], [ 1., 2., 1., 2.], [ 3., 4., 3., 4.]])
np.kron(a, np.ones((2,2))) array([[ 1., 1., 2., 2.], [ 1., 1., 2., 2.], [ 3., 3., 4., 4.], [ 3., 3., 4., 4.]])
But, of'course this is way more generic (and preferable) approach to utilize. eat
Josef
Cheers! Ben Root
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Hi, On Thu, Dec 1, 2011 at 6:52 PM, jonasr <jonas.ruebsam@web.de> wrote:
Hi, is there any possibility to define a numpy matrix, via a smaller given matrix, i.e. in matlab i can do this like
a=[1 2 ; 3 4 ]
A=[a a ; a a ]
so that i finally get
A=[ [1,2,1,2] [3,4,3,4] [1,2,1,2] [3,4,3,4]]
i tried different things on numpy which didn't work any ideas ?
Perhaps something like this: In []: a= np.array([[1, 2], [3, 4]]) In []: np.c_[[a, a], [a, a]] Out[]: array([[[1, 2, 1, 2], [3, 4, 3, 4]], [[1, 2, 1, 2], [3, 4, 3, 4]]]) Regards, eat
thank you
-- View this message in context: http://old.nabble.com/build-numpy-matrix-out-of-smaller-matrix-tp32896004p32... Sent from the Numpy-discussion mailing list archive at Nabble.com.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (4)
-
Benjamin Root -
eat -
jonasr -
josef.pktd@gmail.com