我已经想出了如何做到这一点,但我想检查是否有更有效的方法。
我想要的是 reshape 向量并在第一行中保留样本 0 到 7,然后在第二行中保留样本 8 到 15,依此类推。
这是输出的示例,
array([[ 0, 1, 2, ..., 1221, 1222, 1223],
[ 8, 9, 10, ..., 1229, 1230, 1231],
[ 16, 17, 18, ..., 1237, 1238, 1239],
...,
[ 40, 41, 42, ..., 1261, 1262, 1263],
[ 48, 49, 50, ..., 1269, 1270, 1271],
[ 56, 57, 58, ..., 1277, 1278, 1279]])
输入数据看起来像这样,
array([ 0, 1, 2, ..., 1277, 1278, 1279])
除此之外还有没有更有效的方法
data = np.arange(0, 128*10)
# Reshape for S/H
temp = data.reshape(8*8, -1, order='F')
out = np.zeros((8, int(len(data)/8)))
for idx in range(0, 8):
out[idx] = temp[idx*8: idx*8+8, :].ravel(order = 'F')
最佳答案
抱歉,我的第一个回答是我误读了问题。
这是一个基于纯 numpy 转置和 reshape 的解决方案:
np.transpose( data.reshape(8, 8, -1, order='F'), (1,2,0)).reshape(8,-1)
针对下面的解决方案进行基准测试得出:
关于python - reshape 在每行中维护 N 个样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76565912/