def cal_eigenvalue(cov): """calculate eigenvalue of `cov` matrix""" eigenvalues, eigenvectors = np.linalg.eig(cov) eigen_dict = {value: idx for idx, value in enumerate(eigenvalues)} sort_handler = Sort() sort_eigenvalues = sort_handler.quick(eigenvalues) sort_eigenvalues = sort_eigenvalues[::-1] sort_eigenvectors = [eigenvectors[eigen_dict[sort_value]] for sort_value in sort_eigenvalues] return sort_eigenvalues, sort_eigenvectors
def get_reverse_seq_num(reverse_lst): """get the reverse order number""" num = len(reverse_lst) # map lst to minist range sort_handler = Sort() sort_lst = sort_handler.quick(reverse_lst.copy()) sort_lst_dct = {item: i for i, item in enumerate(sort_lst)} insert_lst = [sort_lst_dct[item] for item in reverse_lst] # count new_lst = [0] * num reverse_num = 0 for item in insert_lst: reverse_num += new_lst[item] for i in range(item): new_lst[i] += 1 return reverse_num