在目录中导入多个 ascii 文件,读取为数组,打印每个文件的行数、列数

import many ascii files in a directory, read as array, print number of rows, columns for each file

作为对数百个 ascii 文件的基本检查,我想仔细检查每个文件的行数和列数是否正确。每个文件的前 6 行不是每个文件包含的 23x23 矩阵的一部分。我已经尝试了各种读取矩阵大小的可能性,我将其变成了注释行(如下),但现在我认为我需要一种新的方法来读取数组,而不是 arcpy 的 listTables。我也愿意使用 pandas 中使用的模块。有任何想法吗?谢谢

import arcpy, numpy
from arcpy import env

env.workspace = r"C:\VMshared\small_example_valley5\SDepth1"

for file in arcpy.ListTables():
    #numpy.loadtxt(file,dtype = float, "#", delimiter = ' ', "#", skiprows = '6')
    outfile = numpy.loadtxt(file, skiprows = '6')
    print numpy.shape(outfile)
    #print enumerate(file)  
    #print len(file) + len(file.T)
    #print len(file) + map(len,file)

我认为 numpy 可以用于此。

for file in arcpy.ListTables():
        outfile = numpy.loadtxt(file, delimiter=" ", skiprows = 6)
        if outfile.shape != (23,23):
            print file + " has an incorrect number of rows or columns"