<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def colinear_pairs(segments, radius=.01, angle=.01, length=None):
 """ Find pairs of segments which are colinear. Parameters segments : (n, 2, (2, 3)) float Two or three dimensional line segments radius : float Maximum radius line origins can differ and be considered colinear angle : float Maximum angle in radians segments can differ and still be considered colinear length : None or float If specified, will additionally require that pairs have a mean vertex distance less than this value from each other to qualify. Returns pairs : (m, 2) int Indexes of segments which are colinear """

    from scipy import spatial

    # convert segments to parameterized origins
    # which are the closest point on the line to
    # the actual zero- origin
    origins, vectors, param = segments_to_parameters(segments)

    # create a kdtree for origins
    tree = spatial.cKDTree(origins)

    # find origins closer than specified radius
    pairs = tree.query_pairs(r=radius, output_type='ndarray')

    # calculate angles between pairs
    angles = geometry.vector_angle(vectors[pairs])

    # angles can be within tolerance of 180 degrees or 0.0 degrees
    angle_ok = np.logical_or(
        util.isclose(angles, np.pi, atol=angle),
        util.isclose(angles, 0.0, atol=angle))

    # apply angle threshold
    colinear = pairs[angle_ok]

    # if length is specified check endpoint proximity
    if length is not None:
        # make sure parameter pairs are ordered
        param.sort(axis=1)
        # calculate the mean parameter distance for each colinear pair
        distance = param[colinear].ptp(axis=1).mean(axis=1)
        # if the MEAN distance is less than specified length consider
        # the segment to be identical: worst case single- vertex
        # distance is 2*length
        identical = distance < length
        # remove non- identical pairs
        colinear = colinear[identical]

    return colinear