0

我正在用 python 编写一个用户定义的函数来有效地从矩阵中提取特定的列块。

我的矩阵是 48 x 16240。数据以某种模式按列组织。
我的目标是从中制作 4 个矩阵。通过选择前 70 列提取第一个矩阵,跳过下一个 210,选择下一个 70,跳过下一个 210,直到矩阵结束。

通过选择第二个 70 列提取第二个矩阵,跳过下一个 210,选择下一个 70,跳过下一个 210,直到矩阵结束。

以与上述相同的方式,通过分别选择第三和第四70列来提取第三和第四矩阵。

可以看出,16240 可以被 70 整除。

有没有办法有效地完成这项工作?

4

2 回答 2

1

列索引i应满足0 =< i modulo (210+70) <= 70-1

于 2019-04-13T00:09:46.727 回答
1

以下是我将如何遍历您要处理的每个列索引:

public static void main(String... args) {
    int blocks = 16240 / 280;
    // process each 280 column block...
    for (int i = 0 ; i < blocks ; i++) {
        // process the first 70 columns of the block
        for (int j = 0 ; j < 70 ; j++) {

            // Compute the column index
            int s = i * 280 + j;

            // Process the column with index 's' here
            System.out.println(s);
        }
    }
}

结果列索引的摘要:

0
1
2
...
67
68
69
280
281
282
283
...
348
349
560
561
562
...
627
628
629
840
841
842
...
...
15748
15749
15960
15961
15962
...
16028
16029

单...是省略的连续数字。Double ... 是省略了全数输出的中间部分。

于 2019-04-13T00:23:51.717 回答