You can use functools.partial() instead of lambda:
from collections import defaultdict from functools import partial defaultdict(partial(numpy.ndarray, 0))
You always need to call defaultdict() , and numpy.ndarray() always requires at least one argument, so you cannot just pass numpy.ndarray here.
source share