Reputation: 150
I am writing a user defined function in python to extract specific chunks of columns from a matrix efficiently.
My matrix is 48 by 16240. The data is organised in some pattern column wise.
My objective is to make 4 matrices out of it. The first matrix is extracted by selecting the first 70 columns, skip the next 210, select the next 70, skip the next 210, till the end of the matrix.
The second matrix is extracted by selecting the second 70 columns, skip the next 210, select the next 70, skip the next 210, till the end of the matrix.
The third and the fourth matrix are extracted by selecting the third and the fourth 70 columns respectively, in the same manner as described above.
As can be observed, 16240 is dividable by 70.
Is there a way to have this efficiently done?
Upvotes: 0
Views: 104
Reputation: 23089
Here's how I would loop over each column index that you want to process:
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);
}
}
}
Summary of resulting column indexes:
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
Single ... is omission consecutive numbers. Double ... is omission of middle section of full number output.
Upvotes: 1
Reputation: 155
The column index i
should satisfy 0 =< i modulo (210+70) <= 70-1
Upvotes: 1