2 回答
TA贡献1828条经验 获得超4个赞
有使用列表推导等更复杂的方法来做到这一点,但这里有一种可能最容易理解的方法:
假设您的数据在一个数组中data。
import numpy as np
data = list(data)
data_subset = []
interval_length = 10,000
n_intervals = int(len(data)/interval_length)
# get every other data interval, starting with the first
for i in range(0, n_intervals, 2):
start_index = i * interval_length
stop_index = start_index + interval_length
data_subset += data[start_index:stop_index]
data_subset = np.array(data_subset)
print(data_subset)
TA贡献1893条经验 获得超10个赞
在较小的列表中尝试此操作,然后将其扩展到较大的列表如何?
ls = [1,2,2,2,2,11,2,2,3,4,44,399,9,9,0]
group_sizes = 3
# getting groups of size 'group_sizes' and then choosing every other one ...
groups = [ls[n:n+group_sizes] for n in range(0, len(ls), group_sizes) if n % 2 == 0]
输出
print groups
# [[1, 2, 2], [2, 2, 3], [9, 9, 0]]
添加回答
举报