All problems
Affine Matrix Decomposition
Problem
Split a 3x3 affine matrix into its translation and linear parts.
The last row must be [0, 0, 1] within 1e-9; otherwise return None. Return [t, L] where t is the translation [M[0][2], M[1][2]] and L is the leading 2x2 block.
Hint
The translation lives in the third column; the linear map lives in the top-left 2x2 block.
Test cases
case 1
in: [[[1,0,5],[0,1,-2],[0,0,1]]]
expected: [[5,-2],[[1,0],[0,1]]]
case 2
in: [[[2,0,0],[0,3,0],[0,0,1]]]
expected: [[0,0],[[2,0],[0,3]]]
case 3
in: [[[0,-1,4],[1,0,7],[0,0,1]]]
expected: [[4,7],[[0,-1],[1,0]]]
case 4
in: [[[1,0,0],[0,1,0],[0,0,1]]]
expected: [[0,0],[[1,0],[0,1]]]
case 5
in: [[[1,0,0],[0,1,0],[1,0,1]]]
expected: null
Starter codePython
def affine_matrix_decomposition(M):
# Your code here
pass5 test cases · run your code against them in the editor