我是python和numpy的新手.我运行了一个我编写的代码,我收到了这条消息:'索引0超出了0号轴的大小为0'没有上下文,我只是想弄明白这意味着什么..问这个可能很傻但它们的轴0和尺寸0是什么意思?index 0表示数组中的第一个值..但我无法弄清楚0和0的意思.
'data'是一个文本文件,在两列中有许多数字.
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
Run Code Online (Sandbox Code Playgroud) 这可能是一个简单的问题.但是,我想澄清以下代码的工作原理.
a = np.arange(8)
a
array([1,2,3,4,5,6,7])
Example Function = a[0:-1]+a[1:]/2.0
Run Code Online (Sandbox Code Playgroud)
在Example Function中,我想提请你注意数组a [0:-1] + a [1:]之间的加号.这是如何运作的?那是什么样的?
例如,加号(加法)是否添加了每个数组的第一个索引?(例如1 + 2)或将所有东西加在一起?(例如1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6 + 7)
然后,我假设/2.0只是将其除以2 ...
提前致谢.
测测