作为输入,我有一个hashmap,它将一个形式为[0,1,0,0,0,1,1,0,0,6,0,1]
的int数组作为键存储,并作为一个键存储一个String标签,即science
。我想要做的是提取数组并将其存放到2D数组中。我想将标签与另一个字符串进行比较,如果匹配,则将1
保存到outputs
,否则保存为零。我认为下面的代码可以做到这一点,但似乎没有。我哪里出错?
double[][] feature_matrix = new double[ number_of_files ][ globo_dict_size ];
int[] outputs = new int [ number_of_files ];
//likely not the best way to do this
for(int z = 0; z < number_of_files; z++)
{
for( Map.Entry< int[] , String > entry : train_freq_count_against_globo_dict.entrySet() )
{
int[] container_of_feature_vector = entry.getKey();
for (int q = 0; q < globo_dict_size; q++)
{
feature_matrix[z][q] = container_of_feature_vector[q];
}
outputs[z] = String.valueOf( entry.getValue() ).equals(LABEL) ? 1 : 0;
}
}