在不影响其他维度的情况下在一维中打乱二维数组
shuffle 2D array in one dimension without effecting other dimension
^没有。不是这样的。 2D。我想在不改变所有其他 D 的情况下洗牌一个 D。加上那是关于 android。离开这里。
我有一个由以下元素组成的二维数组:
示例:
Document 1 = ["I", "am", "awesome"]
Document 2 = ["I", "am", "great", "great"]
字典是:
["I", "am", "awesome", "great"]
所以二维数组看起来像:
[1, 1, 1, 0]
[1, 1, 0, 2]
我想做的是围绕文档的位置进行随机播放,所以我们曾经拥有的位置:
Document 1 = [1, 1, 1, 0]
Document 2 = [1, 1, 0, 2]
我们现在可能有:
Document 2 = [1, 1, 0, 2]
Document 1 = [1, 1, 1, 0]
或者我们可能不会。它应该随机洗牌。
不像this。
如何实现?
我的数据结构是这样的:
int z = 0;
for ( Cell< int[] , String , Integer > cell: train_freq_count_against_globo_dict.cellSet() )
{
int[] container_of_feature_vector = cell.getRowKey();
// 'q' CAN'T be shuffled, 'z' MUST be shuffled.
for (int q = 0; q < globo_dict_size; q++)
{
feature_matrix__train[z][q] = container_of_feature_vector[q];
}
// use 1 and -1 not 0 and 1
outputs__train[z] = String.valueOf( cell.getColumnKey() ).equals(LABEL) ? 1.0 : -1.0;
z++;
}
重点是实现随机梯度下降。
更新:
static double[][] shuffleArray(double[][] input_array)
{
Random rnd = new Random();
for (int i = input_array.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
double[] container = input_array[index];
input_array[index] = input_array[i];
input_array[i] = container;
}
return input_array;
}
这样做!
但不要相信我的话,使用 System.out.println(Arrays.deepToString(input_array));
并自己验证结果。科学。
static double[][] shuffleArray(double[][] input_array)
{
Random rnd = new Random();
for (int i = input_array.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
double[] container = input_array[index];
input_array[index] = input_array[i];
input_array[i] = container;
}
return input_array;
}
^没有。不是这样的。 2D。我想在不改变所有其他 D 的情况下洗牌一个 D。加上那是关于 android。离开这里。
我有一个由以下元素组成的二维数组:
示例:
Document 1 = ["I", "am", "awesome"]
Document 2 = ["I", "am", "great", "great"]
字典是:
["I", "am", "awesome", "great"]
所以二维数组看起来像:
[1, 1, 1, 0]
[1, 1, 0, 2]
我想做的是围绕文档的位置进行随机播放,所以我们曾经拥有的位置:
Document 1 = [1, 1, 1, 0]
Document 2 = [1, 1, 0, 2]
我们现在可能有:
Document 2 = [1, 1, 0, 2]
Document 1 = [1, 1, 1, 0]
或者我们可能不会。它应该随机洗牌。
不像this。
如何实现?
我的数据结构是这样的:
int z = 0;
for ( Cell< int[] , String , Integer > cell: train_freq_count_against_globo_dict.cellSet() )
{
int[] container_of_feature_vector = cell.getRowKey();
// 'q' CAN'T be shuffled, 'z' MUST be shuffled.
for (int q = 0; q < globo_dict_size; q++)
{
feature_matrix__train[z][q] = container_of_feature_vector[q];
}
// use 1 and -1 not 0 and 1
outputs__train[z] = String.valueOf( cell.getColumnKey() ).equals(LABEL) ? 1.0 : -1.0;
z++;
}
重点是实现随机梯度下降。
更新:
static double[][] shuffleArray(double[][] input_array)
{
Random rnd = new Random();
for (int i = input_array.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
double[] container = input_array[index];
input_array[index] = input_array[i];
input_array[i] = container;
}
return input_array;
}
这样做!
但不要相信我的话,使用 System.out.println(Arrays.deepToString(input_array));
并自己验证结果。科学。
static double[][] shuffleArray(double[][] input_array)
{
Random rnd = new Random();
for (int i = input_array.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
double[] container = input_array[index];
input_array[index] = input_array[i];
input_array[i] = container;
}
return input_array;
}