光曲线编程:IndexError:索引46822超出轴0的范围,大小为46822

时间:2019-01-27 18:42:13

标签: python-2.7 machine-learning

我正在尝试重现此GitHub存储库中的代码:

https://github.com/ireis/light_curve_classification/blob/master/feature_extraction.ipynb

我想运行RF.ipynb分类器,我想需要这样做。

但是,当我在Jupyter Notebook中运行代码的这一部分时,我正在尝试重现它:

# Create a list of light-curves

def det_locs(phot_index, nof_objecs):
    s = numpy.zeros(nof_objecs, dtype=int)
    e = numpy.zeros(nof_objecs, dtype=int)
    IDs = []

    curr = phot_index[0]
    IDs += [curr]
    s[0] = 0
    count = 0

    for i, idx in enumerate(phot_index):
        if curr != idx:
            curr = idx
            IDs += [curr]
            e[count] = i + 1
            if count < nof_objecs:
                count = count + 1
                s[count] = i

    e[-1] = len(phot_index)
    return s,e,numpy.array(IDs)

phot_index = numpy.array(phot_df.index)
print(phot_index)
s,e,IDs_ = det_locs(phot_index, nof_objecs)
se = numpy.vstack([s,e]).T

lc_list = []
phot_arr = phot_df[['Mag','MJD','Magerr']].values
print(phot_arr)

for se_ in se:
    lc_list += [phot_arr[se_[0]:se_[1],:]]
print(len(lc_list))

numpy.save('lc_list', lc_list)

我收到此错误消息:

IndexErrorTraceback (most recent call last)
<ipython-input-27-9599626a2296> in <module>()
     27 phot_index = numpy.array(phot_df.index)
     28 print(phot_index)
---> 29 s,e,IDs_ = det_locs(phot_index, nof_objecs)
     30 se = numpy.vstack([s,e]).T
     31 

<ipython-input-27-9599626a2296> in det_locs(phot_index, nof_objecs)
     19             if count < nof_objecs:
     20                 count = count + 1
---> 21                 s[count] = i
     22 
     23     e[-1] = len(phot_index)

IndexError: index 46822 is out of bounds for axis 0 with size 46822

我非常了解编程,我曾尝试查看具有类似错误消息的其他线程,但我无法弄清楚。我尝试添加nof_objec + 1s[count]=i+1,但错误消息消失了,但是下一个代码段不起作用。请帮忙!

我正在使用Python 2.7.12

0 个答案:

没有答案