you could add here right away:

```python
if normalization_factor == 0: return float('nan')
```

and save the computation below in that case...