by karjudev · 4y ago · 0 comments
Nevertheless, my ears perked up at "matrices of different sizes," since that was something I implemented a while back thinking it would find a use-case if it were well advertised.
You can matrix-multiply two arrays of matrices, in which all the matrices have different shapes, as long as matrix "i" in the first array is compatible with matrix "i" in the second array. Like this:
import awkward1 as ak
lefts = ak.Array([
[[1, 2],
[3, 4],
[5, 6]],
[[1, 2, 3, 4],
[5, 6, 7, 8]],
[[1],
[2],
[3],
[4]],
])
rights = ak.Array([
[[7, 8, 9],
[10, 11, 12]],
[[8, 10],
[11, 12],
[13, 14],
[15, 16]],
[[5, 6, 7]],
])
Matrix-multiplying them results in this: >>> (lefts @ rights).tolist()
[
[[ 27, 30, 33],
[ 61, 68, 75],
[ 95, 106, 117]],
[[129, 140],
[317, 348]],
[[ 5, 6, 7],
[10, 12, 14],
[15, 18, 21],
[20, 24, 28]]
]
The left[0]'s 3×2 times right[0]'s 2×3 results in the output's 3×3, etc for i=1 and i=2. This is the kind of operation you wouldn't even be able to talk about if you didn't have jagged arrays.