# Author QFIUNE
# coding=utf-8
# @Time: 2022/4/18 12:25
# @File: 222.py
# @Software: PyCharm
# @contact: 1760812842@qq.com

import numpy

def square_mat_in_trilu_indices(n):
    '''Return a n x n symmetric index matrix, in which the elements are the
    indices of the unique elements of a tril vector
    [0 1 3 ... ]
    [1 2 4 ... ]
    [3 4 5 ... ]
    [...       ]
    '''
    idx = numpy.tril_indices(n)
    #print('numpy.tril_indices(4):',idx)
    #idx = (array([0, 1, 1, 2, 2, 2, 3, 3, 3, 3]),
    #       array([0, 0, 1, 0, 1, 2, 0, 1, 2, 3]))
    tril2sq = numpy.zeros((n,n), dtype=int)
    #print(numpy.arange(n*(n+1)//2)) #[0 1 2 3 4 5 6 7 8 9]
    tril2sq[idx[0], idx[1]] = tril2sq[idx[1], idx[0]] = numpy.arange(n*(n+1)//2)
    return tril2sq

file = 'D:/Project_QF/Amyloid_search/intermediate_file/222.txt'

li = []
with open(file, 'r') as fo:
    lines = fo.readlines()
    for line in lines:
        for i in line.split():
            li.append(float(i.strip()))

idx = square_mat_in_trilu_indices(20)
li = numpy.array(li)


save_dir = 'D:/Project_QF/Amyloid_search/id/'
numpy.savetxt(save_dir + 'hihihi' + '.txt',
                       li, fmt='%f', delimiter='\t')

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐