I have a list of numpy arrays, where each array is of the same rank, for example each array has the same shape of (H, W, C)
.
Assume the list I have has 12 such arrays, e.g.
my_list = [A, B, C, D, E, F, G, H, I, J, K, L]
What I want is given a grid size (in the sample below the grid is 3x4), create a single matrix with the same rank of each array that places the first array in the top left and the last array in the bottom right in an ordered manner, e.g.
[A, B, C, D,
E, F, G, H,
I, J, K, L]
This is only a pseudo result, as the result should be in this case a matrix with the shape of (H*3, W*4, C)
. The example above is only for placement clarification.
How can I achieve that using numpy?
CodePudding user response:
import numpy as np
h = 7
w = 5
c = 10
grid = 3*4
##Creating sample data for list
a = np.random.rand(grid,h,w,c)
my_list = list(a)
####
my_array = np.array(my_list) ## shape (grid,h,w,c)
my_array = my_array.reshape(3,4,h,w,c)
my_array = my_array.transpose(0,2,1,3,4)
your_req_array = my_array.reshape(3*h,4*w,c)