changed defaultdict to {} ; return np.NAN for ZeroDivisionError