直接上代码:
from numpy import *
import numpy as np
Drug_array = zeros((708,708),dtype = int)
f = open('D:\mat_drug_drug.txt')
lines = f.readlines()
Drug_row = 0
for line in lines:
list = line.strip('\n').split(' ')
Drug_array[Drug_row:] = list[:]
Drug_row += 1
print(shape(Drug_array))
np.savetxt('D:\开始吧,少年\数据提取\最终提取\drug_drug.txt',Drug_array,fmt = ['%s']*Drug_array.shape[1],newline = '\n')
直接存TXT中总是科学计数法表示的,想直接看数字不是很方便,用fmt可以是实现不用科学计数法存储。
fmt详细内容:https://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html