如何在ojalgo数组中通过索引获得多个值?



假设我有一个像这样定义的ojAlgo-array

ArrayAnyD<Double> regularArray = ArrayAnyD.PRIMITIVE64.make(10);
regularArray.loopAll((final long[] ref) -> regularArray.set(ref, ref[0]*ref[0]));

,它只包含0到9的平方数,以及一些索引:

long[] idxs = {1, 3, 4, 7, 9}

现在,我想做一些类似于

的事情
slicedArray = regularArray[idxs]

会给我另一个包含1.0, 9.0, 16.0, 49.0, 81.0的数组。我该如何使用ojAlgo呢?

  • regularArray.get(idxs)只给我第一个值。
  • regularArray.sliceSet(idxs, 0)返回从第一个开始的所有值,忽略后面的索引。

我怀疑我需要使用某种形式的正则数组。循环或。loopall,但我不确定如何使它工作

你可以这样做:

ArrayAnyD<Double> array = ArrayAnyD.PRIMITIVE64.make(3, 3, n);
MatrixView<Double> matrices = array.matrices();
// A MatrixView is Iterable,
// but you can also go directly to the matrix you want
matrices.goToMatrix(78);
// Specific rows and columns
Access2D<Double> select = matrices.select(new int[] { 1, 2 }, new int[] { 0 });
Access2D<Double> rows = matrices.rows(1, 2); // All columns
Access2D<Double> columns = matrices.columns(0); // All rows
double value10 = matrices.doubleValue(1, 0);
double value20 = matrices.doubleValue(2, 0);
matrices.goToMatrix(99); // ...

要完成所有这些(完全按照这种方式),您需要v51.3.0-SNAPSHOT或更高版本。

最新更新