I have the following code in which w is a 1D numpy array of compatible dimension, and M is a 4D array,

```
i = 0
for weight in w:
    M[:, :, i, :] *= weight
    i += 1

```

Is there a nicer way to achieve the same effect?