Last active
January 29, 2018 14:59
-
-
Save Hugoberry/2f9bb69ab3ba0c071d7cfe61e1e42102 to your computer and use it in GitHub Desktop.
Matrix Multiplication in Power Query M. Test example = MatrixMultiplication(#table({"A","B"},{{1,2},{3,4}}), #table({"A","B"},{{1,2},{3,4}}))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(A,B) => | |
let | |
//vector multiplication | |
dotProduct = (v1,v2) => | |
List.Accumulate( | |
List.Zip({v1,v2}), | |
0, | |
(agg,_)=> | |
agg+(_{1}*_{0})) | |
in | |
Table.FromRows( | |
List.Accumulate(Table.ToRows(A), | |
{}, | |
(_,ai)=> | |
_& { List.Accumulate(Table.ToColumns(B), | |
{}, | |
(_,bj)=> | |
_&{ dotProduct(ai,bj) }) | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment