我想知道是否有更聪明的方法来从集合中创建默认字典.dict应该有一个空的numpy ndarray作为默认值.
到目前为止,我最好的结果是:
import collections
d = collections.defaultdict(lambda: numpy.ndarray(0))
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否有可能跳过lambda术语并以更直接的方式创建dict.喜欢:
d = collections.defaultdict(numpy.ndarray(0)) # <- Nice and short - but not callable
Run Code Online (Sandbox Code Playgroud)