[Numpy-discussion] TypeError: only integer arrays with one element can be converted to an index

Warren Weckesser warren.weckesser at enthought.com
Sat Apr 3 07:40:10 EDT 2010


Are you sure you wanted to make `left` and `right` tuples that contain 
just one element (which is a numpy array)?  In your code, len(a1) will be 1.

Maybe I am misinterpreting your code, but I think you want this:

left = array([ 107,  594, 1082, 1569, 2057, 2545, 3033, 3520])
right = array([ 133,  621, 1109, 1597, 2085, 2573, 3061, 3550])


Warren


yogesh karpate wrote:
> I am facing the error mentioned in subject line.
> error is encountered at 
> data_temp=filtered[a:b]
> TypeError: only integer arrays with one element can be converted to an 
> index
> what can be error
> The code snippet is  as follows
>
> '''left=some array
> right =some array, both are having same length.
> filtered is datafile(.txt) containing 4000 sample values
> left=(array([ 107,  594, 1082, 1569, 2057, 2545, 3033, 3520]),)
> right=(array([ 133,  621, 1109, 1597, 2085, 2573, 3061, 3550]),)
>
> maxval=empty(a)
> minval=empty(a)
> maxloc=empty(a)
> minloc=empty(a)
> data_temp=empty(a)
> a1=len(left)
> for i in  arange(a1):
>     a=left[i]
>     b=right[i]
>     print a,b
>     data_temp=filtered[a:b]
>    maxloc[i]=data_temp.argmax()
>     maxval[i]=data_temp[maxloc]
>     minloc[i]=data_temp.argmin()
>     minval[i]=data_temp[minloc]
>     maxloc[i] = maxloc[i]-1+left[i]# % add offset of present location
>     minloc[i] = minloc[i]-1+left[i]# % add offset of present location'''
> R_index = maxloc
> R_t   = t[maxloc]
> Thanks in advance
> Regards
> Yogesh
> ------------------------------------------------------------------------
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>   




More information about the NumPy-Discussion mailing list