如何逐列读取文本文件并在每列中查找最小值

时间:2018-02-10 02:56:30

标签: python

我有一个名为store_x_axis.txt的文件,其中包含

0.02153753289089977,0.01666949746870028,0.012109153483800483
0.01812035460886907,0.013230902143324563,0.008647475872060717
0.014703176326838374,0.009792306817948848,0.005185798260320951
0.011285998044807677,0.006353711492574021,0.0020684929408965047
0.00786881976277698,0.002915116167198306,0.0017375569631585819
0.004451641480746282,0.0007780382940847375,0.005199234574898348
0.001100981972369297,0.003962074483552236,0.008660912186638114
0.0023827150833160005,0.007400669808927951,0.01212258979837788
0.00579989336534581,0.010839265134302778,0.015584267410117647

我想在每列中获得最小值:0.001100981972369297,0.0074006698089279510.008647475872060717

我该怎么做?

1 个答案:

答案 0 :(得分:0)

通常,常见任务通常通过库自动/优化。以下代码使用numpy库来处理您的任务:

import numpy as np

arr = np.genfromtxt('file.txt', delimiter=',')

arr_colmin = arr.min(axis=0)