[Python] How can I replace duplicate elements with its first occurrence index in Numpy? (first...

Discussão em 'Python' iniciado por Stack, Julho 27, 2025.

  1. Stack

    Stack Membro Participativo

    for exmaple, I have two arrays: 'x' for actual values, 'I' for their index in array.

    x = [1, 2, 3, 3, 2, 4]
    I = [0, 1, 2, 3, 4, 5]


    in 'x', the 4th value is duplicate one of 3rd value and the 5th value is duplicate one of 2nd value

    Therefore, I want to generate the

    y = [0, 1, 2, 2, 1, 5]


    (containing first occurrence indicies of original array values)

    How can I do this efficiently using python numpy methods?

    Continue reading...

Compartilhe esta Página