# Pastebin uDgZDgDY I whipped up this in raku: use Physics::Measure :ALL; sub infix:<·> { dot-product @^a, @^b } sub dot-product(@mx1, @mx2) { die "Incompatible dimensions for dot product." unless @mx1 == @mx2[0] && @mx1[0] == @mx2; [for ^@mx1 -> $i { [for ^@mx1 -> $j { [+] @mx1[$i;*] >>*<< @mx2[*;$j] }] }] } my @m = [[1m,2m],[3m,4m]]; say @m · [Z] @m; #[[5m^2 11m^2] [11m^2 25m^2]] Since Physics::Measure is strong on illegal combinations and since there are not many realistic random combinations of Units (s^2 anyone) I have not gone random for my example.