IndexError: index 11 is out of bounds for axis 3 with size 11, while list has 12 elements

IndexError: index 11 is out of bounds for axis 3 with size 11, while list has 12 elements

我已经阅读了多篇关于索引错误的帖子,但它们都是从 1 开始的;这里我从索引 0 开始,但我有一个错误

我正在读取一个包含 12 列的文件:

    fid.shape
    for j in range(ny):
        for i in range(nx): 
            fieldMatrix[fcount,i,j,0] = fid["a1"][count]
            print "col0"
            fieldMatrix[fcount,i,j,1] = fid["a2"][count]
            print "col1"
            fieldMatrix[fcount,i,j,2] = fid["a3"][count]
            print "col2"
            fieldMatrix[fcount,i,j,3] = fid["a4"][count]
            print "col3"
            fieldMatrix[fcount,i,j,4] = fid["a5"][count]
            print "col4"
            fieldMatrix[fcount,i,j,5] = fid["a6"][count]
            print "col5"
            fieldMatrix[fcount,i,j,6] = fid["a7"][count]
            print "col6"
            fieldMatrix[fcount,i,j,7] = fid["a8"][count]
            print "col7"
            fieldMatrix[fcount,i,j,8] = fid["a9"][count]
            print "col8"
            fieldMatrix[fcount,i,j,9] = fid["a10"][count]
            print "col9"
            fieldMatrix[fcount,i,j,10] = fid["a11"][count]
            print "col10"
            fieldMatrix[fcount,i,j,11] = fid["a12"][count]
            print "col11"
            count += 1

因为列数是 12 => 最高索引是 11。但是我得到这个:

    (61104, 12)
     col0
     col1
     col2
     col3
     col4
     col5
     col6
     col7
     col8
     col9
     col10
     Traceback (most recent call last):
         fieldMatrix[fcount,i,j,11] = fid["a12"][count]
     IndexError: index 11 is out of bounds for axis 3 with size 11

正在检查 fieldMatrix 的形状:

    (100,402,152,11)

我不得不增加第 12 个元素的 fieldMatrix 的大小。

    (100,402,152,12)