1

I have a set of (numpy) 2d arrays of size N Each element is a 2d numpy array like

set_of_arrays[7] == array([[ 5,  3],
       [ 1,  5],
       [ 8, -1],
       [ 6,  6]])

set_of_arrays[123] = array([[ 5,  3,  1,  5,  8, -1,  6,  6],
       [ 5,  3,  1,  5,  8, -1,  6,  6]])

and so on. The size and shape of each element of set_of_arrays is known. It turns out, that each element of set_of_arrays represents a submatrix (subarray). The question is: for a given 2-d array M, which shape is also known, we want to construct M consistent of subarrays from set_of_arrays. How to construct the matrix M in an automatic way? I saw the np.block() function, but the subarrays should be given explicitely like

M = np.block([[set_of_arrays[0], set_of_arrays[1]], [set_of_arrays[3], set_of_arrays[4]], ...])

However, this needs a lot of hands programming, a lot of brackets [[], [], [], []]. I dont know the number N of subblocks, but it is assured, that the (sub)arrays from set_of_arrays all has correct sizes, allowing to create the matrix M. How to do that? ideally would be something like

Thanks for aswering

Terzi Ak
  • 11
  • 1
  • N is assumed to be something like 1000 ideally i would have something like ```M.subblock[4] = set_of_arrays[4]``` – Terzi Ak Sep 07 '21 at 02:33

1 Answers1

0

I think you could try:

M = np.block([set_of_arrays[i:i + n] for i in range(0, len(set_of_arrays), 2)])
U13-Forward
  • 69,221
  • 14
  • 89
  • 114