-1
我有一個Java方法fill0s(),其輸入較小的矩陣到一個更大的矩陣,理應充滿0:爲什麼創建空白矩陣返回null而不是0.0?
public class PoolingFunctions {
// Fill needed spaces with 0
public static Double[][] fill0s(Double[][] image, int filter_size){
int columns_remaining = filter_size - (image[0].length%filter_size);
int rows_remaining = filter_size - (image.length%filter_size);
// CREATE A MATRIX: HERE LIES THE PROBLEM: //////////////////////////////
Double [][] blank_matrix = new Double [(image.length)+columns_remaining][(image[0].length)+rows_remaining];
for (int i = 0; i<image.length; i++) {
for (int j = 0; j<image[i].length; j++) {
blank_matrix[i][j] = image[i][j];
}
}
return blank_matrix;
}
}
而且調用此方法後:
public class MainPooling{
public static void main(String[] args) {
Double[][] image = { {1.0,1.0,1.0,1.0},
{1.0,1.0,1.0,1.0},
{1.0,1.0,1.0,1.0},
{1.0,1.0,1.0,1.0}
};
Double[][] formatted_image;
formatted_image = PoolingFunctions.fill0s(image,3);
TestMatricesJava.print2dMatrix(formatted_image);
}
}
我得到的以下結果:
1.0 1.0 1.0 1.0 null null
1.0 1.0 1.0 1.0 null null
1.0 1.0 1.0 1.0 null null
1.0 1.0 1.0 1.0 null null
null null null null null null
null null null null null null
我的問題是:爲什麼功能n返回null而不是0.0?