# Calculating sensor-space RMS

**URL:** <https://mne.discourse.group/t/calculating-sensor-space-rms/2475>\
**Category:** Support & Discussions\
**Tags:** eeg, sensor-space, evoked\
**Created:** [January 13, 2021, 10:24am UTC](https://mne.discourse.group/t/calculating-sensor-space-rms/2475 "2021-01-13T10:24:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robpetrosino](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/robpetrosino/32/51_2.png) [@robpetrosino](https://mne.discourse.group/u/robpetrosino)\
**Post date:** [January 13, 2021, 10:24am UTC](https://mne.discourse.group/t/calculating-sensor-space-rms/2475/1 "2021-01-13T10:24:31Z")

</div>

Hello!

I need to calculate timepoint-by-timepoint root mean square (RMS) from a grand-averaged ERP.

1. My script currently calculates the grand averaged ERP using the `mne.grand_average` function, with return an `Evoked` object. How do I calculate the RMS timepoint-by-timepoint of my grand-average waveform? I have tried to do the following:

```python
rms = np.sqrt((ga.data**2).mean())

```

But this will just calculate the overall RMS. I think this is because `ga.data` is just the data without any temporal information. How do I do that? Any suggestion would be much appreciated!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [January 13, 2021, 11:13am UTC](https://mne.discourse.group/t/calculating-sensor-space-rms/2475/2 "2021-01-13T11:13:10Z")

</div>

Hello @robpetrosino,

> [@robpetrosino](#):
>
> ```python
> rms = np.sqrt((ga.data**2).mean())
> 
> ```

the call to `mean()` is the problem here: it calculates the mean across **all** elements in the array. However, you’d like to calculate the mean values for each time point separately. Therefore, you need to tell `mean()` which axis to use. This should do the trick for you:

```python
rms = np.sqrt((ga.data**2).mean(axis=0))

```

---

<div class="post-metadata">

**Author:** ![robpetrosino](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/robpetrosino/32/51_2.png) [@robpetrosino](https://mne.discourse.group/u/robpetrosino)\
**Post date:** [January 13, 2021, 3:02pm UTC](https://mne.discourse.group/t/calculating-sensor-space-rms/2475/3 "2021-01-13T15:02:13Z")

</div>

Grrr…I did not catch that argument of the `mean` function, so I got the same result by doing a `for` loop:

```python
for n in range(0, len(ga.times):
    rms = np.sqrt( (ga.data[:, n] ** 2).mean() )

```

Thanks!!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [January 13, 2021, 4:17pm UTC](https://mne.discourse.group/t/calculating-sensor-space-rms/2475/4 "2021-01-13T16:17:06Z")

</div>

> [@robpetrosino](#):
>
> I did not catch that argument of the `mean` function

Yes it’s always something to keep in mind when working with NumPy 🙂 Great to hear it’s working for you now!
