I'm trying to do matrix multiplication in multik (...
# mathematics
j
I'm trying to do matrix multiplication in multik (https://github.com/Kotlin/multik). It seems like I should get a 2 X 3 matrix, but I get an error message that says "Array shapes don't match: [2, 1] != [1, 3]". Can anyone say if this is a bug or am I doing something horribly wrong?
Copy code
val a = mk.ndarray(floatArrayOf(1.0f, 2.0f), 2, 1)
val b = mk.ndarray(floatArrayOf(1.0f, 2.0f, 3.0f), 1, 3)

val result = a * b
println(result)
a
They are not matrices, they are nd arrays. Multik works in numpy paradigm where multiplication is element by element. You need to use
dot
operation to dot operation for matrix product.
There are three different ways to separate element-by-element behavior from matrix behavior: 1. Use different operators on the same structures. 2. Use different types (for example wrap 2d ndarray in a Matrix type). 3. Use different context for those operations. Multik uses variant 1.
j
That makes sense, thanks a lot for the help.