Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-229

Complex Matrix Multiply

Problem

Multiply two complex matrices A and B, where each entry is a pair [real, imaginary].

Use (a+bi)(c+di) = (ac - bd) + (ad + bc)i and return the product as a matrix of [real, imaginary] pairs.

Hint

Track real and imaginary parts separately with the complex multiplication rule.

Test cases

case 1
in: [[[[1,1],[0,0]],[[0,0],[1,-1]]],[[[1,0],[0,0]],[[0,0],[1,0]]]]
expected: [[[1,1],[0,0]],[[0,0],[1,-1]]]
case 2
in: [[[[0,1]]],[[[0,1]]]]
expected: [[[-1,0]]]
case 3
in: [[[[1,1]]],[[[1,-1]]]]
expected: [[[2,0]]]
case 4
in: [[[[1,0],[2,-1]],[[0,1],[3,0]]],[[[2,1],[0,0]],[[-1,2],[1,1]]]]
expected: [[[2,6],[3,1]],[[-4,8],[3,3]]]
Starter codePython
def complex_matrix_multiply(A, B):
    # Your code here
    pass

4 test cases · run your code against them in the editor