Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert primitive double array to Double array

With the Apache common math library I get back a primitive double array.

  RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse();

  double[][] temp = pInverse.getData();

I need to convert temp to a Double[][]

  Double[][] inverse = new Double[][]temp;
like image 484
DCR Avatar asked Mar 11 '26 16:03

DCR


1 Answers

If you are using Java 8+ you can use :

Double[][] inverse = Arrays.stream(temp)
        .map(d -> Arrays.stream(d).boxed().toArray(Double[]::new))
        .toArray(Double[][]::new);
like image 197
YCF_L Avatar answered Mar 13 '26 06:03

YCF_L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!