def matrix_to_parameters(matrix):
    """ Affine matrix to parameter vector.

    Returns parameter vector layed out as
    2d:
        [a00, a01, a02, a10, a11, a12]
    3d:
        [a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23]
    """
    if matrix.shape[0] == 4:
        assert matrix.shape == (4, 4)
        trafo = matrix[0].tolist() + matrix[1].tolist() + matrix[2].tolist()
    else:
        assert matrix.shape == (3, 3)
        trafo = matrix[0].tolist() + matrix[1].tolist()
    return trafo