public static double [ ] pairwiseMultiply ( double [ ] a , double [ ] b ) { if ( a . length != b . length ) { throw new RuntimeException ( "Can't pairwise multiple different lengths: a.length=" + a . length + " b.length=" + b . length ) ; } double [ ] result = new double [ a . length ] ; for ( int i = 0 ; i < result . length ; i ++ ) { result [ i ] = a [ i ] * b [ i ] ; } return result ; }
Assumes that both arrays have same length .