【发布时间】:2021-05-12 03:26:54
【问题描述】:
如何随机读取50%的文件数:
files = glob.glob("*.txt")
##suppose files are objects
for fi in files:
#I want to implement through the for loop
data = np.genfromtxt(fi, ...)
编辑:我想通过for循环来实现,在我的另一个问题中,文件是对象。
【问题讨论】:
-
随机打乱文件列表并遍历前半部分元素。
-
random.sample(files, len(files) // 2) -
我想通过for循环来实现
-
@deceze 您应该将其发布为答案;它比我的好:)
-
什么意思,“想通过for循环来实现”?
标签: python