我对 python 和 numpy 都是新手。我运行了我编写的代码,我收到了这条消息:'index 0 is out of bounds for axis 0 with size 0' 没有上下文,我只想弄清楚这意味着什么。问这个可能很愚蠢但是轴 0 和大小 0 是什么意思?索引 0 表示数组中的第一个值.. 但我无法弄清楚轴 0 和大小 0 的含义。
“数据”是一个文本文件,两列中有很多数字。
x = np.linspace(1735.0,1775.0,100)
column1 = (data[0,0:-1]+data[0,1:])/2.0
column2 = data[1,1:]
x_column1 = np.zeros(x.size+2)
x_column1[1:-1] = x
x_column1[0] = x[0]+x[0]-x[1]
x_column1[-1] = x[-1]+x[-1]-x[-2]
experiment = np.zeros_like(x)
for i in range(np.size(x_edges)-2):
indexes = np.flatnonzero(np.logical_and((column1>=x_column1[i]),(column1<x_column1[i+1])))
temp_column2 = column2[indexes]
temp_column2[0] -= column2[indexes[0]]*(x_column1[i]-column1[indexes[0]-1])/(column1[indexes[0]]-column1[indexes[0]-1])
temp_column2[-1] -= column2[indexes[-1]]*(column1[indexes[-1]+1]-x_column1[i+1])/(column1[indexes[-1]+1]-column1[indexes[-1]])
experiment[i] = np.sum(temp_column2)
return experiment