在一维上打乱二维数组而不影响另一维度

不,不是那样的。二维的。我想在一维上打乱,而完全不改变另一维度。而且那是关于安卓的,把它拿走。

我有一个由元素组成的二维数组:

例如:

文档1 = ["我", "是", "很棒的"]文档2 = ["我", "是", "很好的", "很好的"]

字典是:

["我", "是", "很棒的", "很好的"]

所以二维数组看起来像这样:

[1, 1, 1, 0][1, 1, 0, 2]

我想做的就是打乱文档的位置,所以我们曾经有:

文档1 = [1, 1, 1, 0]文档2 = [1, 1, 0, 2]

现在我们可能会有:

文档2 = [1, 1, 0, 2]文档1 = [1, 1, 1, 0]

或者可能不会。这应该是随机打乱的。

不像这个

如何实现这个?

我的数据结构看起来像这样:

int z = 0;for ( Cell< int[] , String , Integer > cell: train_freq_count_against_globo_dict.cellSet() ){                  int[] container_of_feature_vector = cell.getRowKey();    // 'q' 不能被打乱,'z' 必须被打乱。    for (int q = 0; q < globo_dict_size; q++)     {        feature_matrix__train[z][q] = container_of_feature_vector[q];     }    // 使用1和-1而不是0和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);      // 简单交换      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);      // 简单交换      double[] container = input_array[index];      input_array[index] = input_array[i];      input_array[i] = container;    }    return input_array;  }

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注