简体   繁体   中英

C# Matrix*Vector = DotProduct Using MathNet Library

I am currently building a FeedForward Neural Network library on C# and am struggling with matrix multiplication.

To those who are familiar with MathNet library; is there an existing function where it can take a Matrix and Vector (or versa) and return a Scalar as dot product?

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)

Install MathNet.Spatial nuget

using MathNet.Spatial.Euclidean;

Then...

在此处输入图片说明

The Vector3D struct comes from the spatial ecluidian namespace

the * operator between two vector objects in mat.net.numerics is their dot product.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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