![](/img/trans.png)
[英]Splitting a Java 2D array (4x4) into smaller ones (2x2) and joining them again
[英]Resample 2D Array from 2x2 to 4x4
我想重新樣品從2×2的二維數組data
以4×4 newdata
原始源二維數組data
:
我要尋找一個在newdata
到目前為止,我已經嘗試過如下;
public class Test {
static int[][] data = new int[2][2];
static int[][] newdata = new int[4][4];
public static void main(String[] args) {
data[0][0] = 00;
data[0][1] = 01;
data[1][0] = 10;
data[1][1] = 11;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
// I NEED LOGIC HERE TO FILL newdata 2D ARRAY as a re-sampled output
}
}
}
}
實現可以是任何語言,例如 c++、php、c#、java 等。
任何幫助表示贊賞,提前致謝。
將您的循環更改為:
for (int k = 0; k < 4; k++)
{
for (int l = 0; l < 4; l++)
{
newdata[k][l] = data[k/2][l/2];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.