<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def thresh(data, threshold, threshold_type='hard'):
 r"""Threshold data This method perfoms hard or soft thresholding on the input data Parameters data : np.ndarray, list or tuple Input data array threshold : float or np.ndarray Threshold level(s) threshold_type : str {'hard', 'soft'} Type of noise to be added (default is 'hard') Returns ------- np.ndarray thresholded data Raises ------ ValueError If `threshold_type` is not 'hard' or 'soft' Notes ----- Implements one of the following two equations: * Hard Threshold .. math:: \mathrm{HT}_\lambda(x) = \begin{cases} x & \text{if } |x|\geq\lambda \\ 0 & \text{otherwise} \end{cases} * Soft Threshold .. math:: \mathrm{ST}_\lambda(x) = \begin{cases} x-\lambda\text{sign}(x) & \text{if } |x|\geq\lambda \\ 0 & \text{otherwise} \end{cases} Examples -------- array([-4, 2, 3, -1, 0, 2, -4, 6, -9, 7]) array([-4, 0, 0, 0, 0, 0, -4, 6, -9, 7]) array([[ 4.17022005e-01, 7.20324493e-01, 1.14374817e-04], [ 3.02332573e-01, 1.46755891e-01, 9.23385948e-02], [ 1.86260211e-01, 3.45560727e-01, 3.96767474e-01]]) array([[ 0.217022 , 0.52032449, -0. ], [ 0.10233257, -0. , -0. ], [-0. , 0.14556073, 0.19676747]]) """


    data = np.array(data)

    if threshold_type not in ('hard', 'soft'):
        raise ValueError('Invalid threshold type. Options are "hard" or'
                         '"soft"')

    if threshold_type == 'soft':
        return np.around(np.maximum((1.0 - threshold /
                         np.maximum(np.finfo(np.float64).eps, np.abs(data))),
                         0.0) * data, decimals=15)

    else:
        return data * (np.abs(data) >= threshold)