Skip to content

Instantly share code, notes, and snippets.

@Hugoberry
Last active January 29, 2018 14:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Hugoberry/2f9bb69ab3ba0c071d7cfe61e1e42102 to your computer and use it in GitHub Desktop.
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}}))
(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