2016-04-28 99 views
1

我在想,是否在Apache Math Commons庫中有一個用於元素級乘法的特徵,類似於MATLAB中使用的特徵,即生成的矩陣C等於矩陣A乘以矩陣B中的對應值。我想避免編寫我自己的版本,因爲我知道線性代數包是針對這些類型的操作進行了高度優化的,並且如果已經存在(已優化),我不想在自己的實現上失去性能。Java Apache Common Commons Element-Wise矩陣乘法

在MATLAB中:C = A.*BA的尺寸必須等於B的s。

+1

我失去了你的問題的一部分,你說你走過去['RealMatrix'接口(https://commons.apache.org/proper/commons-math/ apidocs/org/apache/commons/math3/linear/RealMatrix.html)並沒有找到任何東西。當你做了_that_看看[這裏](http://glimmpse.samplesizeshop.org/documentation/JavaStatistics/1.2/api/edu/cudenver/bios/matrix/MatrixUtils.html#getElementWiseProduct%28org.apache.commons.math3 .linear.RealMatrix,%20org.apache.commons.math3.linear.RealMatrix%29)。 –

+0

對不起,回覆遲了,我看了我不敢相信我沒有找到它!感謝您清理它:) –

+0

請注意,我發佈的最後一個鏈接是發生在實施您所需的第三方庫。沒有理由感覺不好:) –

回答

0

我用於從Apache數學ebeMultiplication的RealVectors。我不知道是否有矩陣的等價函數,我查了一下,但沒有找到。至於載體:

RealVector output = new ArrayRealVector(o); // o and y are double[] 
    RealVector expected = new ArrayRealVector(y); 
    RealVector errors = expected.subtract(output);  
    RealVector delta = errors.ebeMultiply(output);