# Grand average of all subjects per condition

**URL:** https://mne.discourse.group/t/grand-average-of-all-subjects-per-condition/3327
**Category:** Support & Discussions
**Created:** [June 28, 2021, 7:09pm UTC](https://mne.discourse.group/t/grand-average-of-all-subjects-per-condition/3327 "2021-06-28T19:09:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![armine-garibyan](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/armine-garibyan/32/610_2.png) [@armine-garibyan](https://mne.discourse.group/u/armine-garibyan)
#### Post date: [June 28, 2021, 7:09pm UTC](https://mne.discourse.group/t/grand-average-of-all-subjects-per-condition/3327/1 "2021-06-28T19:09:28Z")

</div>

MNE-Python version: 0.23.0  
Operating system: McOS BigSur 11.4

Dear MNE forum,

First of all, thank you very much for your valuable feedback here as well as for the 8-hour YouTube tutorial on MNE. I am sorry in advanced for probably asking trivial things. I’m not advanced in Python and a beginner in MNE.

I have created the epochs, and then since I have 2 conditions, for each subject I created evokeds. That is, I have 2 evokeds per subject. Now I want to create the grand average across all subjects for each condition. As I see it, I should thus end up having 2 evoked objects across subjects (for each of the two conditions). When I use the function mne.grand\_average, I get an error.

The documentation requires all\_inst [list of `Evoked`] or [`AverageTFR`]. So, I created a list of all evoked objects (per subject) for the two conditions.

```python
all_evokeds_col = [ev_col_1, ev_col_2, ev_col_3, ...]
all_evokeds_non_col = [ev_non_col_1, ev_non_col_2, ev_non_col_3,...]

grand_average_col = mne.grand_average(all_evokeds_col)
grand_average_non_col = mne.grand_average(all_evokeds_non_col)

```

But the grand\_average function throws the following error:

```python
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-72-50206ec155ec> in <module>
----> 1 grand_average_col = mne.grand_average(all_evokeds_col)

~/opt/anaconda3/envs/mne/lib/python3.9/site-packages/mne/utils/numerics.py in grand_average(all_inst, interpolate_bads, drop_bads)
    574 
    575 inst_type = type(all_inst[0])
--> 576 _validate_type(all_inst[0], (Evoked, AverageTFR), 'All elements')
    577 for inst in all_inst:
    578 _validate_type(inst, inst_type, 'All elements', 'of the same type')

~/opt/anaconda3/envs/mne/lib/python3.9/site-packages/mne/utils/check.py in _validate_type(item, types, item_name, type_name)
    423 type_name = ', '.join(type_name)
    424 _item_name = 'Item' if item_name is None else item_name
--> 425 raise TypeError(f"{_item_name} must be an instance of {type_name}, "
    426 f"got {type(item)} instead")
    427 

TypeError: All elements must be an instance of Evoked or AverageTFR, got <class 'list'> instead

```

I think I might be doing something fundamentally wrong, probably it is the list of evokeds (all\_inst). So, I would be extremely grateful if someone could tell me. I’ve seen all examples on the MNE website and read the documentation but I’m struggling to compute the average across all subjects per condition.

All the best,  
Armine

---

<div class="post-metadata">

### Author: ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)
#### Post date: [June 28, 2021, 7:52pm UTC](https://mne.discourse.group/t/grand-average-of-all-subjects-per-condition/3327/2 "2021-06-28T19:52:35Z")

</div>

it seems that at least one of `ev_col_1`, `ev_col_2`, etc is a list (probably with an evoked inside it). You’ll need to figure out why that is. For example, this could easily happen if you had saved the evokeds to disk after creating them, then re-loaded before doing the grand average, because `mne.read_evokeds` will return a (possibly length-one) list when reading from file. (the reason it does that is that the `fif` format can store multiple evokeds in a single file, if desired).

If you can’t figure out why, you’ll need to share more of your code (the part that creates the variables `ev_col_1` etc).

---

<div class="post-metadata">

### Author: ![armine-garibyan](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/armine-garibyan/32/610_2.png) [@armine-garibyan](https://mne.discourse.group/u/armine-garibyan)
#### Post date: [June 28, 2021, 9:28pm UTC](https://mne.discourse.group/t/grand-average-of-all-subjects-per-condition/3327/3 "2021-06-28T21:28:36Z")

</div>

Dear Dan,

Thanks a lot for your feedback! You were right, I indeed saved all the averaged epochs and then loaded them from a disk, that’s why the error emerged. But now following your recommendation, I create the evokeds and then immediately create the grand average, and everything works as I said. Thank you so much!
