All problems
Cofactor Matrix
Problem
Compute the 3x3 cofactor matrix C of a 3x3 matrix A.
C[i][j] = (-1)^(i+j) * det(minor(A, i, j)), where the minor deletes row i and column j.
Hint
Signs alternate like a checkerboard starting with + at (0, 0).
Test cases
case 1
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: [[1,0,0],[0,1,0],[0,0,1]]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [[-3,6,-3],[6,-12,6],[-3,6,-3]]
case 3
in: [[[2,0,0],[0,3,0],[0,0,4]]]
expected: [[12,0,0],[0,8,0],[0,0,6]]
case 4
in: [[[1,2,3],[0,1,4],[5,6,0]]]
expected: [[-24,20,-5],[18,-15,4],[5,-4,1]]
Starter codePython
def cofactor_matrix(A):
# Your code here
pass4 test cases · run your code against them in the editor