human
Complete this python program:
def fit_matched_points(src_pts, tgt_pts, rotate=True, translate=True, scale=False, tol=None, x0=None, out='trans'):
assistant
#Here is the Python code you requested.

    """Find a transform between matched sets of points.
    This minimizes the squared distance between two matching sets of points.
    Uses :func:`scipy.optimize.leastsq` to find a transformation involving
    a combination of rotation, translation, and scaling (in that order).
    Parameters
    src_pts : array, shape = (n, 3)
    Points to which the transform should be applied.
    tgt_pts : array, shape = (n, 3)
    Points to which src_pts should be fitted. Each point in tgt_pts should
    correspond to the point in src_pts with the same index.
    rotate : bool
    Allow rotation of the ``src_pts``.
    translate : bool
    Allow translation of the ``src_pts``.
    scale : bool
    Number of scaling parameters. With False, points are not scaled. With
    True, points are scaled by the same factor along all axes.
    tol : scalar | None
    The error tolerance. If the distance between any of the matched points
    exceeds this value in the solution, a RuntimeError is raised. With
    None, no error check is performed.
    x0 : None | tuple
    Initial values for the fit parameters.
    out : \params\ | \trans\
    In what format to return the estimate: \params\ returns a tuple with
    the fit parameters; \trans\ returns a transformation matrix of shape
    (4, 4).
    Returns
    One of the following, depending on the ``out`` parameter:
    trans : array, shape = (4, 4)
    Transformation that, if applied to src_pts, minimizes the squared
    distance to tgt_pts.
    params : array, shape = (n_params, )
    A single tuple containing the translation, rotation and scaling
    parameters in that order.
    """
    from scipy.optimize import leastsq
    src_pts = np.atleast_2d(src_pts)
    tgt_pts = np.atleast_2d(tgt_pts)
    if (src_pts.shape != tgt_pts.shape):
        raise ValueError('src_pts    and    tgt_pts    must    have    same    shape    (got    {0},    {1})'.format(src_pts.shape, tgt_pts.shape))
    rotate = bool(rotate)
    translate = bool(translate)
    scale = int(scale)
    if translate:
        src_pts = np.hstack((src_pts, np.ones((len(src_pts), 1))))
    param_info = (rotate, translate, scale)
    if (param_info == (True, False, 0)):
        def error(x):
            (rx, ry, rz) = x
            trans = rotation3d(rx, ry, rz)
            est = dot(src_pts, trans.T)
            return (tgt_pts - est).ravel()
        if (x0 is None):
            x0 = (0, 0, 0)
    elif (param_info == (True, False, 1)):
        def error(x):
            (rx, ry, rz, s) = x
            trans = (rotation3d(rx, ry, rz) * s)
            est = dot(src_pts, trans.T)
            return (tgt_pts - est).ravel()
        if (x0 is None):
            x0 = (0, 0, 0, 1)
    elif (param_info == (True, True, 0)):
        def error(x):
            (rx, ry, rz, tx, ty, tz) = x
            trans = dot(translation(tx, ty, tz), rotation(rx, ry, rz))
            est = dot(src_pts, trans.T)
            return (tgt_pts - est[:, :3]).ravel()
        if (x0 is None):
            x0 = (0, 0, 0, 0, 0, 0)
    elif (param_info == (True, True, 1)):
        def error(x):
            (rx, ry, rz, tx, ty, tz, s) = x
            trans = reduce(dot, (translation(tx, ty, tz), rotation(rx, ry, rz), scaling(s, s, s)))
            est = dot(src_pts, trans.T)
            return (tgt_pts - est[:, :3]).ravel()
        if (x0 is None):
            x0 = (0, 0, 0, 0, 0, 0, 1)
    else:
        raise NotImplementedError(('The    specified    parameter    combination    is    not    implemented:    rotate=%r,    translate=%r,    scale=%r' % param_info))
    (x, _, _, _, _) = leastsq(error, x0, full_output=True)
    if ((tol is not None) or (out == 'trans')):
    ...