I'm wondering if there's a more clever way to create a default dict from collections. The dict should have an empty numpy ndarray as default value.
My best result is so far:
import collections
d = collections.defaultdict(lambda: numpy.ndarray(0))
However, i'm wondering if there's a possibility to skip the lambda term and create the dict in a more direct way. Like:
d = collections.defaultdict(numpy.ndarray(0)) # <- Nice and short - but not callable
np.concat()can be used to accumulate arrays. If the arrays are large and few, this may be more efficient. So, I like the proposed solution above.base = defaultdict(lambda : np.ndarray(0)); base = np.concatenate((base, new_array)