[Python] Is there a NumPy magic to generate this array?

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I have an array a of increasing indexes, e.g. [2 5 9 10], which indicates positions of value change. Assuming the output values are 0 and 1, I want to get array b:

    [0 0 1 1 1 0 0 0 0 1 0]


    Is there a NumPy magic to transform a into b?

    Continue reading...

Compartilhe esta Página