def group_data(data, grouping):
"""
Group the data with respect to the supplied `grouping' specification
(i.e., "GROUPING" columns of a spectrum). The channel counts of the
same group are summed up and assigned to the FIRST channel of this
group, while the OTHRE channels are all set to ZERO.
"""
data_grp = np.array(data)
for i in reversed(range(len(data))):
if grouping[i] == 1:
# the beginning channel of a group
continue
else:
# other channels of a group
data_grp[i-1] += data_grp[i]
data_grp[i] = 0
assert np.isclose(sum(data_grp), sum(data))
return data_grp
评论列表
文章目录