How do you elegantly create a NumPy ndarray from (1D-)arrays of different lengths, padding the remainder?
The arrays are always 1D, they have different lengths (maximum length varied between 20 and 100).
Say there is
a = range(40)
b = range(30)
The resultant ndarray should be
X = [[0,1,2,3,...,39,40],
[0,1,2,...29,30,0,0,...,0]]
Hacky solution
Creating an intermediary
I = [a,b]
and padding to a maximum via
I[1].extend([0] * (maximum - len(I[1])))
which can then be converted via
X = np.array(I)
works but is there nothing built-in / available via PyPI / more pythonic?
np.lib.pad(I, (0, len(b)), 'constant', constant_values=(0,0))did not work (added an extra row)