[Python] IndexError: too many indices for array

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to graph G versus l1. The data is in the file that I loaded from an excel file. The excel file is 14x250 so there are 14 arguments, each with 250 data points.

    So here is the code in question:

    # format for CSV file:
    header = ['l1', 'l2', 'l3', 'l4', 'l5', 'EI', 'S', 'P_right', 'P1_0',
    'P3_0', 'w_left', 'w_right', 'G_left', 'G_right']

    def loadfile(filename, skip=None):
    skip = set(skip or [])
    with open(filename) as f:
    cr = csv.reader(f, quoting=csv.QUOTE_NONNUMERIC)
    return np.array(row for i,row in enumerate(cr) if i not in skip)

    outputs_l1 = [loadfile('{}.csv'.format(p)) for p in p3_arr]
    col = {name: i for i, name in enumerate(header)}

    for data in outputs_l1:
    xs = data[:, col["l1" ]]
    gl = data[:, col["G_left" ]] * 1000.0 # column 12
    gr = data[:, col["G_right"]] * 1000.0 # column 13


    After running the entire program, I receive the error message:

    Traceback (most recent call last):
    File "C:/Users/Chris/Desktop/Work/Python Stuff/New Stuff from Brenday 8 26 2014/CD_ssa_plot(2).py", line 115, in <module>
    xs = data[:, col["l1" ]]
    IndexError: too many indices for array


    and before I ran into that problem, I had another involving the line a few below the one the above error message refers to:

    Traceback (most recent call last): File "FILE", line 119, in <module>
    gl = data[:, col["G_left" ]] * 1000.0 # column 12
    IndexError: index 12 is out of bounds for axis 1 with size 12

    Continue reading...

Compartilhe esta Página