文件之间的python均值 [英] python mean between file
问题描述
我现在创建一个包含一千多个文件的列表(基本上现在我有一个包含文件名的列表),目的是使这个我认为愿意做这个事情的人(假设asch文件有20行):
I create a list of more than a thousand file (Basically now I have a list with the name of the file) now in order to make the man I thought to do something like this (suppose asch file have 20 lines):
matrix = np.zeros((len(file_list),10))
然后我要给矩阵充电:.
then I'm going to charge the matrix .. with something like :
for i,j in zip(len(file_list)) :
matrix[i].append(np.genfromtxt('name1',usecols=(1,)))
现在有一种方法可以不定义文件行数???
Now is there a way not to define the number of file's line ???
然后..我如何在此文件之间取平均值?
then .. how can i make a mean between this file ??
糟糕,我看到numpy数组没有附加..我该怎么办
Ops I see that numpy array have not append ..how can I do
推荐答案
首先,您可以将它们存储在列表中:
First, you can just store them in a list:
My_list = []
for i,j in zip(len(file_list)) :
My_list.append(np.genfromtxt('name1',usecols=(1,)))
假设所有文件的行和列数相同,则可以将其转换为numpy数组:
Assuming that all your files have the same number of lines and columns, you can then convert it to a numpy array:
My_list = np.array(My_list)
My_list
现在是一个numpy数组,其维数对应于已加载文件的大小+一个维数,对应于文件数.
My_list
is now a numpy array, with dimensions corresponding to the size of the loaded files + one corresponding to the number of files.
请注意,我没有检查文件的加载方式.
Note that I did not check the way you're loading files.
这篇关于文件之间的python均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!