我试着得到数据的每个子组的平均值,按一系列指数分组。我可能没有正确地解释它,但下面的示例代码应该清楚地指出我想做什么。
import numpy as np
means = [data[i].mean(axis=0) for i in indices]
# data.shape = (17 492, 3 650)
# data.dtype = float64
# indices.shape = (30, 17 492)
# indices.dtype = bool
字符串
这里,data
是一个N * M
浮点数组,indices
是一个L * N
布尔掩码数组。索引的每个L
是指示要一起平均的第l
组数据的布尔掩码。
根据数据大小,这是我的过程中最密集的部分。如果有一种方法可以完全使用NumPy函数来实现这一点,我想重构它。
2条答案
按热度按时间4sup72z81#
更小的样本:
字符串
您的列表理解:
型
整个数组方法,创建一个更大的数组,其中
nan
用于屏蔽的值。有一整套np.nan...
函数可以从浮点数组中剥离nan
,并在没有它们的情况下进行计算。型
值匹配;我不知道时机。我从这个例子中得到的可能不适用于你的更大的情况。
查看
nanmean
代码,我发现了一种更直接的方法:型
zsbz8rwp2#
我想你想这么做?
字符串