# Difficulty Indexing EpochsTFR Object with Boolean Mask

**URL:** <https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750>\
**Category:** Support & Discussions\
**Tags:** epochs\
**Created:** [January 28, 2025, 12:20pm UTC](https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750 "2025-01-28T12:20:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hironobu0529](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/hironobu0529/32/3847_2.png) [@hironobu0529](https://mne.discourse.group/u/hironobu0529)\
**Post date:** [January 28, 2025, 12:20pm UTC](https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750/1 "2025-01-28T12:20:12Z")

</div>

Dear MNE-Python Community,

I am currently working with an `EpochsTFR` object and encountering challenges when attempting to select specific epochs using a boolean mask. Below are the details of my setup and the issue:

- **MNE Version** : 1.9.0
- **Operating System** : Ubuntu 20.04

**Code Snippet** :

```python
import numpy as np
import mne

# Assuming 'power_epochs' is an existing EpochsTFR object
valid_idx = [
    False, True, False, True, False, True, False, True,
    False, False, True, False, False, True, True, False,
    True, True, False, True, True, False, True, True,
    True, True, True, True, True, False
]

# Attempting to select epochs using the boolean mask
matching_epochs = power_epochs[valid_idx]

```

**Issue** :

When executing the above code, I encounter the following error:

```python
IndexError: list assignment index out of range

```

**Observations** :

- The length of `valid_idx` matches the number of epochs in `power_epochs`.
- Using integer indices instead of a boolean mask does not resolve the issue.
- Accessing `power_epochs.selection[valid_idx]` returns the expected array of selected indices.

**Request** :

I am seeking guidance on the correct method to index or select specific epochs from an `EpochsTFR` object using a boolean mask or an alternative approach. Any insights or suggestions to resolve this issue would be greatly appreciated.

Thank you for your assistance.

Best regards,

Hironobu Nakamura

---

<div class="post-metadata">

**Author:** ![tsbinns](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tsbinns/32/4543_2.png) [@tsbinns](https://mne.discourse.group/u/tsbinns)\
**Post date:** [January 28, 2025, 12:38pm UTC](https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750/2 "2025-01-28T12:38:39Z")

</div>

Hello,

Could you please share some more info from the error traceback? Does it happen to look like this?

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/8/87ef539b9a392c8acbdbf6519b7b0143be537759.png)

If so, this is a bug that was [recently fixed](https://github.com/mne-tools/mne-python/pull/13028) and is available in the development version of MNE. If you don’t want to use the development version, a workaround is to initialise the drop log in the `EpochsTFRArray` object as `drop_log=tuple([() for _ in range(n_epochs)])` instead of the default `None`.

If it’s not the same error, would you be able to share the `EpochsTFR` object you are having issues with and we can look into it.

Best,  
Thomas

---

<div class="post-metadata">

**Author:** ![hironobu0529](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/hironobu0529/32/3847_2.png) [@hironobu0529](https://mne.discourse.group/u/hironobu0529)\
**Post date:** [January 28, 2025, 11:15pm UTC](https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750/3 "2025-01-28T23:15:50Z")

</div>

> [@hironobu0529](#):
>
> `matching_epochs = power_epochs[valid_idx]`

###### 

Dear Thomas,

Thank you for your prompt response.

The error message I encountered is indeed identical to the one you described. Therefore, I plan to try the MNE development version to see if it resolves the issue.

For your reference, here is the basic information of the `EpochsTFR` object I’m working with:

- **Type** : `<class 'mne.time_frequency.tfr.EpochsTFR'>`
- **Data shape** : (30, 66, 30, 1501) (epochs, channels, frequencies, time points)
- **Number of epochs** : 30
- **Number of channels** : 66
- **Number of frequencies** : 30
- **Number of time points** : 1501
- **Time range** : 7.0 to 10.0 seconds
- **Frequency range** : 2.0 to 200.0 Hz
- **Channels** : [‘eega1-ref’, ‘eega2-ref’, ‘pola4-pola3’, ‘pola5-pola4’, ‘pola6-pola5’, ‘pola3-pola6’, ‘pola8-pola7’, ‘pola9-pola8’, ‘pola10-pola9’, ‘pola11-pola10’, ‘pola12-pola11’, ‘pola13-pola12’, ‘pola14-pola13’, ‘pola15-pola14’, ‘pola16-pola15’, ‘pola17-pola16’, ‘pola18-pola17’, ‘pola7-pola18’, ‘pola20-pola19’, ‘pola21-pola20’, ‘pola22-pola21’, ‘pola23-pola22’, ‘pola24-pola23’, ‘pola19-pola24’, ‘pola26-pola25’, ‘pola27-pola26’, ‘pola28-pola27’, ‘pola29-pola28’, ‘pola30-pola29’, ‘pola25-pola30’, ‘pola32-pola31’, ‘pola33-pola32’, ‘pola34-pola33’, ‘pola35-pola34’, ‘pola36-pola35’, ‘pola31-pola36’, ‘pola38-pola37’, ‘pola39-pola38’, ‘pola40-pola39’, ‘pola41-pola40’, ‘pola42-pola41’, ‘pola37-pola42’, ‘pola44-pola43’, ‘pola45-pola44’, ‘pola46-pola45’, ‘pola47-pola46’, ‘pola48-pola47’, ‘pola43-pola48’, ‘pola50-pola49’, ‘pola51-pola50’, ‘pola52-pola51’, ‘pola53-pola52’, ‘pola54-pola53’, ‘pola55-pola54’, ‘pola56-pola55’, ‘pola57-pola56’, ‘pola58-pola57’, ‘pola59-pola58’, ‘pola60-pola59’, ‘pola49-pola60’, ‘polb2-polb1’, ‘polb3-polb2’, ‘polb4-polb3’, ‘polb5-polb4’, ‘polb6-polb5’, ‘polb1-polb6’]
- **Channel types** : [‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’, ‘seeg’]
- **Metadata columns** : Index([‘time’, ‘cue’, ‘valence’, ‘vividness’, ‘valence\_RT’, ‘vividness\_RT’], dtype=‘object’)

I hope this information is helpful. Thank you again for your assistance.

Best regards,

Hironobu Nakamura

---

<div class="post-metadata">

**Author:** ![sotpapad](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/sotpapad/32/2184_2.png) [@sotpapad](https://mne.discourse.group/u/sotpapad)\
**Post date:** [January 29, 2025, 8:10am UTC](https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750/4 "2025-01-29T08:10:36Z")

</div>

In theory using a list of indices should work.

Depending on what you need to do afterward a workaround could be to use the `.get_data()` method to keep the data as a numpy array. Then you could work directly on that or create an `EpochsTFRArray` object.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [February 5, 2025, 8:11am UTC](https://mne.discourse.group/t/difficulty-indexing-epochstfr-object-with-boolean-mask/10750/5 "2025-02-05T08:11:01Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
