code: public static float[] slice(float[] data, int[] index) {
          int n = index.length;
          float[] x = new float[n];
          for (int i = 0; i < n; i++) {
              x[i] = data[index[i]];
          }
  
          return x;
      }
docs: Returns a slice of data for given indices.