python教程—数组索引太多-Python实用宝典

# python教程—数组索引太多

```# 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']

skip = set(skip or [])
with open(filename, *args) as f:
return np.array(row for i,row in enumerate(cr) if i not in skip)
#plot data
outputs_l1 = [loadfile('C:\Users\Chris\Desktop\Work\Python Stuff\BPCROOM - Shingles analysis\ERR analysis\l_1 analysis//BS(1) ERR analysis - l_1 - P_3 = {}.csv'.format(p)) for p in p3_arr]

col = {name:i for i,name in enumerate(header)}

fig = plt.figure()
for data,color in zip(outputs_l1, colors):
xs  = data[:, col["l1"     ]]
gl = data[:, col["G_left" ]] * 1000.0    # column 12
gr = data[:, col["G_right"]] * 1000.0    # column 13
plt.plot(xs, gl, color + "-", gr, color + "--")
for output, col in zip(outputs_l1, colors):
plt.plot(output[:,0], output[:,11]*1E3, col+'--')
plt.ticklabel_format(axis='both', style='plain', scilimits=(-1,1))
plt.xlabel('\$l1 (m)\$')
plt.ylabel('G \$(J / m^2) * 10^{-3}\$')
plt.xlim(xmin=.2)
plt.ylim(ymax=2, ymin=0)

```

```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
```

```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
```

​Python实用宝典 (pythondict.com)