1

I have the following list that I convert to a numpy.array:

sells = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 599]
np_sells = np.array(sells)
print(np_sells)

>> 

    array([  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
           599], dtype=int64)

I want to know the index of the first element that is different from 0, I try with np.nonzero() method and get this:

a = np.nonzero(np_sells)
print(a)

>> (array([13], dtype=int64),)

What I really need is that 13 to go look for that number in another list of dates (I am working on a time series), but if I try this code I keep getting the same error:

dates_list = ['01-07-2014','01-08-2014','01-09-2014','01-10-2014','01-11-2014','01-12-2014','01-01-2015','01-02-2015','01-03-2015','01-04-2015','01-05-2015','01-06-2015','01-07-2015','01-08-2015','01-09-2015','01-10-2015','01-11-2015','01-12-2015','01-01-2016','01-02-2016','01-03-2016','01-04-2016','01-05-2016','01-06-2016','01-07-2016']

dates_list[a]

>>> TypeError: list indices must be integers or slices, not tuple

I know it must be really simple but I'm stuck.

1 Answer 1

3

Its because a is a tuple. You can't pass it as index. So we can try this (sorry your question is not clear to me, so this could seem unclear to you):

another_array = a[0]
idx = another_array[#Enter the index you want here]
print(dates_list[idx])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.