Last active
September 13, 2024 16:45
-
-
Save william2ai/61cdc49eb1b7358cf3e8968f57197f60 to your computer and use it in GitHub Desktop.
EEG Pre_Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# 加载数据 | |
data = np.load('eeg.npy') | |
# 获取数据的形状 | |
num_channels, num_timepoints, num_samples = data.shape | |
# 对每个 channel 进行正则化 | |
for i in range(num_samples): | |
for j in range(num_channels): | |
# 取出当前 channel 的数据 | |
current_data = data[j, :, i] | |
# 计算均值和标准差 | |
mean = np.mean(current_data) | |
std = np.std(current_data) | |
# 避免标准差为 0 的情况 | |
if std != 0: | |
data[j, :, i] = (current_data - mean) / std | |
else: | |
data[j, :, i] = current_data - mean | |
# 保存标准化后的数据 | |
np.save('normalized_eeg.npy', data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment