You can use np.ndarray.reshape then use np.column_stack here.
inp = {
"a": np.zeros((1000, 3, 4)),
"b": np.zeros((1000, 5, 2)),
"c": np.zeros((1000, 7, 8, 2,)),
"d": np.zeros((1000, 6,)),
}
arrs = [arr.reshape(1000, -1) for arr in inp.values()]
out = np.column_stack(arrs)
array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]])
out.shape
(1000, 140) # 3*4 + 5*2 + 7*8*2 + 6 = 140
For columns you can use itertools.product and use itertools.chain.from_iterable here.
from itertools import product, chain
shapes = [(name, arr.shape[1:]) for name, arr in inp.items()]
def col_names(val):
*prefix, shape = val
names = [map(str, range(i)) for i in shape]
return map('_'.join, product(prefix, *names))
cols = [*chain.from_iterable(col_names(val) for val in shapes)]
len(cols) # 140
cols
['a_0_0',
'a_0_1',
'a_0_2',
...
'a_2_2',
'a_2_3',
'b_0_0',
'b_0_1',
...
'b_4_1',
'c_0_0_0',
...
'c_6_6_1',
'c_6_7_0',
'c_6_7_1',
'd_0',
...
'd_5']
Now use cols as columns in your dataFrame.
pd.DataFrame(out, columns=cols)
a_0_0 a_0_1 a_0_2 a_0_3 a_1_0 a_1_1 ... d_0 d_1 d_2 d_3 d_4 d_5
0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
.. ... ... ... ... ... ... ... ... ... ... ... ... ...
995 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
996 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
997 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
998 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
999 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0
[1000 rows x 140 columns]