我想从一个double数组中创建一个向量,并希望将该向量乘以矩阵。有人知道我如何实现吗?以下是一个非常简单的示例,我希望能够使其工作。
// Create the matrix (using JAMA)
Matrix a = new Matrix( [[1,2,3],[1,2,3],[1,2,3]] );
// Create a vector out of an array
...
// Multiply the vector by the matrix
...
我想从一个double数组中创建一个向量,并希望将该向量乘以矩阵。有人知道我如何实现吗?以下是一个非常简单的示例,我希望能够使其工作。
// Create the matrix (using JAMA)
Matrix a = new Matrix( [[1,2,3],[1,2,3],[1,2,3]] );
// Create a vector out of an array
...
// Multiply the vector by the matrix
...
这是一个所需操作的简单示例:
double[][] array = {{1.,2.,3},{1.,2.,3.},{1.,2.,3.}};
Matrix a = new Matrix(array);
Matrix b = new Matrix(new double[]{1., 1., 1.}, 1);
Matrix c = b.times(a);
System.out.println(Arrays.deepToString(c.getArray()));
结果:
[[3.0, 6.0, 9.0]]
换句话说,就是:
Matrix a = new Matrix( [[1,2,3],[1,2,3],[1,2,3]] );
Matrix b = new Matrix( [[1,2,3]] ); // this is a vector
Matrix c = a.arrayTimes(b.transpose); // transpose so that the inner dimensions agree
从我阅读文档的内容来看,我认为这个方案是可行的。
double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
Matrix A = new Matrix(vals);
来自 http://math.nist.gov/javanumerics/jama/doc/Jama/Matrix.html
Matrix
类API(http://math.nist.gov/javanumerics/jama/doc/Jama/Matrix.html)是你的好伙伴,可以获得更多选项 :) - Grzegorz Szpetkowski