I'm trying to combine different length numpy arrays as one could equivalently do using lists with itertools.zip_longest
. Say I have:
a = np.array([1, 5, 9, 13])
b = np.array([2, 6])
With itertools
one could interleave these two arrays using chain
and zip_longest
, and fill the missing values with say 0
:
from itertools import chain, zip_longest
list(chain(*zip_longest(*[a, b], fillvalue=0)))
# [1, 2, 5, 6, 9, 0, 13, 0]
Is there a simple way to do this using numpy
that I'm missing?