# Issue with Assigning Values to Sub-Epochs in MNE Epochs Object

**URL:** https://mne.discourse.group/t/issue-with-assigning-values-to-sub-epochs-in-mne-epochs-object/10718
**Category:** Support & Discussions
**Tags:** eeg, epochs
**Created:** [January 19, 2025, 5:47am UTC](https://mne.discourse.group/t/issue-with-assigning-values-to-sub-epochs-in-mne-epochs-object/10718 "2025-01-19T05:47:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jianyang](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jianyang/32/4061_2.png) [@Jianyang](https://mne.discourse.group/u/Jianyang)
#### Post date: [January 19, 2025, 5:47am UTC](https://mne.discourse.group/t/issue-with-assigning-values-to-sub-epochs-in-mne-epochs-object/10718/1 "2025-01-19T05:47:27Z")

</div>

Dear MNE Experts,

I am working with an `EpochsArray` object that contains different `event_id` categories. However, I encountered an issue when trying to apply a z-score transformation to the data corresponding to each specific `event_id`. Below is a description of the problem:

### **Epoch Structure**

```python
<EpochsArray | 278 events (all good), -0.5 – 2 s, baseline off, ~32.0 MB, data loaded,
 '1': 34
 '2': 34
 '3': 36
 '4': 37
 '5': 33
 '6': 37
 '7': 33
 '8': 34>

```

### **Working Example**

When applying a moving average transformation across all data in the `EpochsArray`, it works perfectly:

```python
 for i_shape1 in range(epoch._data.shape[0]): 
        epoch._data[i_shape1,:,:] = JY_basic_func.moving_average(epoch._data[i_shape1,:,:] , np.ones(window) / window)

```

### **Problematic Code**

However, when I attempt to apply a z-score transformation to each `event_id` subset using the following code, the data inside `epoch[i_key]._data` does not update:

```python
for i_key in epoch.event_id.keys():
        if z_type =='channel':
            epoch[i_key]._data = zscore(epoch[i_key]._data,axis=1)

```

After running this, `epoch[i_key]._data` remains unchanged.

### **Question**

Is there a convenient way to modify the data corresponding to each `event_id` within an `EpochsArray` structure? Any suggestions or guidance would be greatly appreciated.

#### System Information:

- MNE version: e.g. 1.5.1
- operating system: e.g. Windows 10

Thank you for your time and support!

Best regards,  
Jianyang

---

<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 19, 2025, 9:18pm UTC](https://mne.discourse.group/t/issue-with-assigning-values-to-sub-epochs-in-mne-epochs-object/10718/2 "2025-01-19T21:18:33Z")

</div>

Hello!

> [@Jianyang](#):
>
> However, when I attempt to apply a z-score transformation to each `event_id` subset using the following code, the data inside `epoch[i_key]._data` does not update:

I believe indexing `Epochs` creates a copy, so you’re modifying a copy and immediately discarding it … I don’t know from the top of my head how you could solve this, but I suppose you could build something with the help of [`Epochs.apply_function()`](https://mne.tools/stable/generated/mne.Epochs.html#mne.Epochs.apply_function) and take care of the different event types inside the function you call (you’d need to pass the events array for this).

Good luck,  
Richard

---

<div class="post-metadata">

### Author: ![Jianyang](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/jianyang/32/4061_2.png) [@Jianyang](https://mne.discourse.group/u/Jianyang)
#### Post date: [January 20, 2025, 11:42am UTC](https://mne.discourse.group/t/issue-with-assigning-values-to-sub-epochs-in-mne-epochs-object/10718/3 "2025-01-20T11:42:37Z")

</div>

Get it. Now I have created a dictionary to store the z-score data. Thank you very much.

---

<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: [January 27, 2025, 11:43am UTC](https://mne.discourse.group/t/issue-with-assigning-values-to-sub-epochs-in-mne-epochs-object/10718/4 "2025-01-27T11:43:10Z")

</div>

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