简体   繁体   English

C# Matrix*Vector = DotProduct 使用 MathNet 库

[英]C# Matrix*Vector = DotProduct Using MathNet Library

I am currently building a FeedForward Neural Network library on C# and am struggling with matrix multiplication.我目前正在 C# 上构建一个前馈神经网络库,并且正在努力处理矩阵乘法。

To those who are familiar with MathNet library;对于那些熟悉 MathNet 库的人; is there an existing function where it can take a Matrix and Vector (or versa) and return a Scalar as dot product?是否有一个现有的 function 可以接受矩阵和向量(或相反)并返回标量作为点积?

Thanks in advance.提前致谢。

在此处输入图像描述

You are correct, there doesn't seem to be an existing function for it.你是对的,它似乎没有现有的功能。 You can use the following:您可以使用以下内容:

double dotproduct = 0;
for (i = 0; i <= m.ColumnCount; i++) {
    dotproduct += m.Column(i).DotProduct(v);
}

A solution to dot product two vectors in MathNet (was not able to figure out how to do it with a matrix)在 MathNet 中对两个向量进行点积的解决方案(无法弄清楚如何用矩阵来做)

Install MathNet.Spatial nuget安装 MathNet.Spatial nuget

using MathNet.Spatial.Euclidean;

Then...那么...

在此处输入图片说明

The Vector3D struct comes from the spatial ecluidian namespace Vector3D结构体来自空间 ecluidian 命名空间

the * operator between two vector objects in mat.net.numerics is their dot product. mat.net.numerics 中两个向量对象之间的 * 运算符是它们的点积。

Also, if you multiply an mxn matrix with a vector of length n, you get the scalar dot product results of each row of the matrix with the vector in the as a vector in the output.此外,如果将一个 mxn 矩阵与一个长度为 n 的向量相乘,您将得到矩阵的每一行与 output 中的向量的标量点积结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM