summing up values of columns from multiple files

后端 未结 3 1616
遥遥无期
遥遥无期 2021-01-15 01:55

I have a small problem here, I\'m trying to sum up entries from multiple files (50), and each of them contain 3 columns. for example, using the first 3 files: file1.txt, fi

3条回答
  •  情深已故
    2021-01-15 02:28

    In [1]: import numpy as np
    
    In [2]: from StringIO import StringIO
    
    In [3]: txt ="""2 3 4
       ...: 1 5 6
       ...: 5 4 7"""
    
    In [4]: f = StringIO(txt)
    
    In [5]: arr = np.loadtxt(f,dtype = int)
    
    In [6]: np.sum(arr,axis = 0)
    Out[6]: array([ 8, 12, 17])
    

提交回复
热议问题