Right Matrix Division in C#

偶尔善良 提交于 2019-12-08 03:54:48

问题


How can I perform a Right Matrix Division in C#?. In MATLAB the code would be

AA(I) = ((X(I,:)-mu)/si)*(X(I,:)-mu)';
%where,
%I is index
%AA is a matrix of 1330x1 double
%X is a matrix of 1330x158 double
%mu is a matrix of 1x134 double
%si is a matrix of 134x134 double

For now I am using jagged arrays to perform all my computations. Is there a library I should use that can do efficient matrix computations?

Update with using MathNet LinearAlgebra

 /* MathNet Matrix tests */
            Matrix<double> AA = Matrix<double>.Build.Dense(1330, 1, 1.0);
            Matrix<double> XX = Matrix<double>.Build.Dense(1330, 158, 1.0);
            Matrix<double> si = Matrix<double>.Build.Dense(134, 134, 1.0);
            Matrix<double> mu = Matrix<double>.Build.Dense(1, 134, 1.0);

            AA.Row(0) = ((XX.Row(0) - mu.Row(0)) * si.Inverse()) * (XX.Row(0) - mu.Row(0)).Transpose();

update:

AA.SetRow(0, ((XX.Row(0) - mu.Row(0)) * si.Inverse()) * ((XX.Row(0) - mu.Row(0)).ToRowMatrix().Transpose()));

As suggested by @ander-biguri, the above is the implementation using MathNet Numerics library.

Question: I get an error stating that Transpose cannot be applied to vectors. How can I achieve AA(I) = ((X(I,:)-mu)/si)*(X(I,:)-mu)' statement, what am I doing wrong here?

来源:https://stackoverflow.com/questions/40635178/right-matrix-division-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!