我试图在python中实现一个公共平均引用函数。其思想是计算所有EEG通道上的信号平均值,并在每个时间点从每个通道的EEG信号中减去它。这个函数的输入是一个名为NumPy数组的试用。测试是一个三维数组,包含这种形式的脑电数据:(试验x时间x通道)。例如:
trials.shape is (240, 2048, 17) 输出将是经过处理的信号阵列。这是我目前的代码:
# Common Average Reference
import numpy as np
def car(trials):
signal = []
for tr in trials:
tr = np.subtract(tr,(np.dot(np.mean(tr, axis=1), np.ones((0, np.size(tr, axis=1))))))
signal.append(tr)
return signalBnd返回此错误:
ValueError: shapes (2048,) and (0,17) not aligned: 2048 (dim 0) != 0 (dim 0)你对如何解决这个问题有什么建议吗?提前谢谢你!
发布于 2022-02-04 21:25:47
喔-我不明白共同平均数的定义。正如沃伦·韦克塞 评论中指出的那样,汽车是每个电极上的值,而不是随着时间的推移。因此,平均应该通过通道维数来计算。使用keepdims=True使形状兼容,以便仍然可以通过广播进行减法:
>>> car = np.mean(trials, axis=2, keepdims=True)
>>> car.shape
(240, 2048, 1)你可以利用NumPy的广播业
>>> import numpy as np
>>> trials = np.random.random((240, 2048, 17))
(WRONG) >>> car = np.mean(trials, axis=0) # calculate the Common Average Reference across all the trials for each channel
>>> car.shape
(2048, 17)
>>> tnew = trials - carhttps://stackoverflow.com/questions/70992167
复制相似问题