IndexError:用作索引的数组必须是整数(或布尔)类型

时间:2016-02-24 16:01:21

标签: python biosppy

我使用ipython notebook和biosppy 0.1.2来分析EDA数据。我得到以下IndexError:

IndexError                                Traceback (most recent call last)
<ipython-input-21-0191d6af629b> in <module>()
     37         eda_final = eda_real_list
     38 
---> 39         out = EDA.eda(signal=eda_in_time_ok, sampling_rate=100.0,   show=True)
     40 
     41 

C:\Python27\Lib\site-packages\biosppy\signals\eda.pyc in eda(signal, sampling_rate, show)
     89                           amplitudes=amps,
     90                           path=None,
---> 91                           show=True)
     92 
     93     # output

C:\Python27\Lib\site-packages\biosppy\plotting.py in plot_eda(ts, raw, filtered, onsets, peaks, amplitudes, path, show)
    351     ax2.plot(ts, filtered, linewidth=MAJOR_LW, label='Filtered')
    352 
--> 353     ax2.vlines(ts[onsets], ymin, ymax,
    354                color='m',
    355                linewidth=MINOR_LW,

IndexError: arrays used as indices must be of integer (or boolean) type

这是我的简单代码:

from biosppy.signals import eda as EDA

for pict in blocks_images:

    picture = imread('C:\Users\Roberta\Desktop\Arousal-Valence_setup-last\\'+pict)


    for subj in range(0,len(blocks[pict]['ecg'])):

        time_start=5   # time in seconds of image onset
        time_stop=35   # time in seconds of image off


        eda_data = blocks[pict]['eda'][subj]

        time_eda_1 = [eda[0] for eda in eda_data]
        time_eda = np.array(time_eda_1)-time_eda_1[0]
        index_start = map(int,list(time_eda)).index(time_start)
        index_stop = map(int,list(time_eda)).index(time_stop)


        eda_in_time_ok = map(float, [ii[1] for ii in eda_data[index_start:index_stop]if ii[1] != 0.0])

        out = EDA.eda(signal=eda_in_time_ok, sampling_rate=100.0, show=True)

我试着按照我在这里找到的其他帖子解决它,没有任何积极的结果。 有人可以告诉我这是什么问题,我该如何解决? 不幸的是,我在编程方面很陌生,而且我没有找到很多关于bioSPPy的文档可以帮助我。

非常感谢!

1 个答案:

答案 0 :(得分:1)

EDA.eda()期待np.array不是python列表。

添加import numpy as np,然后更改行

eda_in_time_ok = map(float, [ii[1] for ii in eda_data[index_start:index_stop]if ii[1] != 0.0])

到这个

eda_in_time_ok = np.array([float(ii[1]) for ii in eda_data[index_start:index_stop] if ii[1] != 0.0])