[Python] In an array of counters that reset, find the start-end index for counter

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    Given an array that looks like this:

    values [0, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6, 0, 0, 1, 2, 3]
    index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


    If I search for index 3, I want to get the indexes of the start and end indexes for that counter, before it is reset again, which is 2 - 6.

    And for index 10, I want to get 8 - 13. And for index 16, I want to get 16 - 18.

    How can I achieve this in numpy?

    Continue reading...

Compartilhe esta Página