code: def svd_thresh_coef(data, operator, threshold, thresh_type='hard'):
      
  
      if not callable(operator):
          raise TypeError('Operator must be a callable function.')
  
      # Get SVD of data matrix
      u, s, v = calculate_svd(data)
  
      # Diagnalise s
      s = np.diag(s)
  
      # Compute coefficients
      a = np.dot(s, v)
  
      # Get the shape of the array
      array_shape = np.repeat(np.int(np.sqrt(u.shape[0])), 2)
  
      # Compute threshold matrix.
      ti = np.array([np.linalg.norm(x) for x in
                     operator(matrix2cube(u, array_shape))])
      threshold *= np.repeat(ti, a.shape[1]).reshape(a.shape)
  
      # Threshold coefficients.
      a_new = thresh(a, threshold, thresh_type)
  
      # Return the thresholded image.
      return np.dot(u, a_new)
docs: Threshold the singular values coefficients
  
      This method thresholds the input data using singular value decomposition
  
      Parameters
      ----------
      data : np.ndarray
          Input data array, 2D matrix
      operator : class
          Operator class instance
      threshold : float or np.ndarray
          Threshold value(s)
      threshold_type : str {'hard', 'soft'}
          Type of noise to be added (default is 'hard')
  
      Returns
      -------
      np.ndarray thresholded data
  
      Raises
      ------
      ValueError
          For invalid string entry for n_pc