Skip to content

Instantly share code, notes, and snippets.

@Hugoberry
Last active January 29, 2018 14:59
Embed
What would you like to do?
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