Or even np.average which would work for both version.

```
np.average(((y_pred - y_true) ** 2), weights=sample_weight)
```