python - Load numeric data from file and generate mapping between columns -
the dataset:
1 6.6156e-13 2 3.0535e-13 3 6.2224e-13 4 3.0885e-13 5 1.1117e-10 6 3.8244e-11 7 5.3916e-11 8 1.7591e-11 9 2.2733e-10
i want extract coefficients , perform operation . coefficients 6.6156e-13, 3.0535e-13 etc.
how extract coefficients while preserving id(id int value associated coefficients)? want using python.i think can use dictionary , have key-value pairs.
code:
text_file = open("sens-buck.txt", "r") lines = text_file.readlines() a=[] l in lines: print (l) text_file.close()
this you'll need do:
load data using
np.loadtxt
generate mapping using dict comprehension
x = np.loadtxt("sens-buck.txt").reshape(-1, 2) # load text file # https://stackoverflow.com/a/45688392/4909087 mapping = {int(k) : v k, v in x.tolist()} # create mapping print(mapping)
output:
{1: 6.6156e-13, 2: 3.0535e-13, 3: 6.2224e-13, 4: 3.0885e-13, 5: 1.1117e-10, 6: 3.8244e-11, 7: 5.3916e-11, 8: 1.7591e-11, 9: 2.2733e-10}
Comments
Post a Comment