1

When I'm using 2d array maps, everything works fine. When I start using 1d arrray's this error occurs; IndexError: unsupported iterator index. This is the error I'm talking about:

In [426]: y = Series( [0,1,0,1] )
In [427]: arr1 = np.array( [10,20] )
In [428]: arr2 = np.array( [[10,20],[30,40]] )
In [429]: arr2[ y, y ]
Out[429]: array([10, 40, 10, 40])
In [430]: arr1[ y ]

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-430-25b98edce1f3> in <module>()
----> 1 arr1[ y ]

IndexError: unsupported iterator index

I'm using the latest Anaconda distribution with NumPy 1.8.1. Maybe this is related to a NumPy bug discussed here? Could anybody tell me what is causing this error?

1 Answer 1

2

You need to either convert the Series to a array, or vice-versa. Indexers must be 1-d for a 1-d object.

In [11]: arr1[y.values]
Out[11]: array([10, 20, 10, 20])

In [12]: Series(arr1)[y]
Out[12]: 
0    10
1    20
0    10
1    20
dtype: int64
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, that's perfect. Looks like I need to work on my understanding of numpy indexing.
if need be you can convert a 2-d to a 1-d with arr.ravel()
Good to know. I was also working around with arr2[y,0] but wanted to figure out what was happening in case I was not understanding how numpy works (which I obv wasn't!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.