def threshold_img(data, threshold, mask=None, mask_out='<STR_LIT>'):
if mask is not None:<EOL><INDENT>mask = threshold_img(mask, threshold, mask_out=mask_out)<EOL>return data * mask.astype(bool)<EOL><DEDENT>if mask_out.startswith('<STR_LIT:b>'):<EOL><INDENT>data[data < threshold] = <NUM_LIT:0><EOL><DEDENT>elif mask_out.startswith('<STR_LIT:a>'):<EOL><INDENT>data[data > threshold] = <NUM_LIT:0><EOL><DEDENT>return data<EOL>
Threshold data, setting all values in the array above/below threshold
    to zero.
    Args:
        data (ndarray): The image data to threshold.
        threshold (float): Numeric threshold to apply to image.
        mask (ndarray): Optional 1D-array with the same length as the data. If
            passed, the threshold is first applied to the mask, and the
            resulting indices are used to threshold the data. This is primarily
            useful when, e.g., applying a statistical threshold to a z-value
            image based on a p-value threshold.
        mask_out (str): Thresholding direction. Can be 'below' the threshold
            (default) or 'above' the threshold. Note: use 'above' when masking
            based on p values.