Reputation: 11
I've been trying to create a matrix of matrices using the numpy function numpy.array() and am facing difficulties
I'm specifically trying to create the following matrix
[
[
[ [
[ 1 ,2 ] [ 1 , 2 ]
[ 3 ,4 ] [ 3 , 4 ]
] , ]
]
[
[ [
[ 1 ,2 ] [ 1 , 2 ]
[ 3 ,4 ] [ 3 , 4 ]
] , ]
]
]
more precisely like this one
I've tried the following line in Jupyter
x = np.array( [
[ [ 1,2 ] ,[ 3, 4] ] , [ [ 1,2 ] ,[ 3, 4] ] ,
[ [ 1,2 ] ,[ 3, 4] ] , [ [ 1,2 ] ,[ 3, 4] ]
])
but what it does is puts all the 2X2 matrices in row-wise form.
I'm not able to take 2( 2X2 ) matrices in row form and replicate them in columns or 2 ( 2X2 ) matrices in column form and replicate them into rows
Any idea how to create this using numpy.array() or any other approach( using numpy functions )
it seem simple but I'm finding difficulties in formulating the code. Thanks in advance.
Upvotes: 0
Views: 2254
Reputation: 1287
>>> a = np.array([[[[1,2],[3,4]], [[1,2], [3,4]]], [[[1,2],[3,4]], [[1,2], [3,4]]]])
>>> a
array([[[[1, 2],
[3, 4]],
[[1, 2],
[3, 4]]],
[[[1, 2],
[3, 4]],
[[1, 2],
[3, 4]]]])
Upvotes: 1