I have a list of list of m-by-n NumPy arrays that I get from a third-party library, e.g.,
import numpy
x0 = numpy.random.rand(1000, 1000) # x_i likewise
a = [[x0], [x1, x2], [x3, x4, x5]] # and more
I now need to flatten this structure, e.g.,
b = numpy.concatenate(a)
# b = [x0, x1, x2, x3, x4, x5]
The arrays x are however so large that both a and b don't fit into memory at the same time, so Python is oom-killed at concatenate.
Can I flatten a into a contiguous numpy array while deallocating the elements of a along the way?