<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cpu_source_extraction(in1, tolerance, neg_comp):
 """ The following function determines connectivity within a given wavelet decomposition. These connected and labelled structures are thresholded to within some tolerance of the maximum coefficient at the scale. This determines whether on not an object is to be considered as significant. Significant objects are extracted and factored into a mask which is finally multiplied by the wavelet coefficients to return only wavelet coefficients belonging to significant objects across all scales. INPUTS: in1 (no default):
 Array containing the wavelet decomposition. tolerance (no default):
 Percentage of maximum coefficient at which objects are deemed significant. OUTPUTS: objects*in1 The wavelet coefficients of the significant structures. objects The mask of the significant structures. """


    # The following initialises some variables for storing the labelled image and the number of labels. The per scale
    # maxima are also initialised here.

    scale_maxima = np.empty([in1.shape[0],1])

    objects = np.empty_like(in1, dtype=np.int32)
    object_count = np.empty([in1.shape[0],1], dtype=np.int32)

    # The following loop uses functionality from the ndimage module to assess connectivity. The maxima are also
    # calculated here.

    for i in range(in1.shape[0]):
        if neg_comp:
            scale_maxima[i] = np.max(abs(in1[i,:,:]))
        else:
            scale_maxima[i] = np.max(in1[i,:,:])
        objects[i,:,:], object_count[i] = ndimage.label(in1[i,:,:], structure=[[1,1,1],[1,1,1],[1,1,1]])

    # The following removes the insignificant objects and then extracts the remaining ones.

    for i in range(-1,-in1.shape[0]-1,-1):
        if neg_comp:
            if i==(-1):
                tmp = (abs(in1[i,:,:])>=(tolerance*scale_maxima[i]))*objects[i,:,:]
            else:
                tmp = (abs(in1[i,:,:])>=(tolerance*scale_maxima[i]))*objects[i,:,:]*objects[i+1,:,:]
        else:
            if i==(-1):
                tmp = (in1[i,:,:]>=(tolerance*scale_maxima[i]))*objects[i,:,:]
            else:
                tmp = (in1[i,:,:]>=(tolerance*scale_maxima[i]))*objects[i,:,:]*objects[i+1,:,:]

        labels = np.unique(tmp[tmp>0])

        for j in labels:
            objects[i,(objects[i,:,:]==j)] = -1

        objects[i,(objects[i,:,:]>0)] = 0
        objects[i,:,:] = -(objects[i,:,:])

    return objects*in1, objects