[Python] More efficient version of numpy.searchsorted for two arrays that are both sorted...

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

  1. Stack

    Stack Membro Participativo

    According to the documentation, given two arrays a, b of size n, m, numpy.searchsorted(a, b) uses bisect library to find the location of each b in array a. The complexity of this algorithm should be m log n. Note that this algorithm does not require b to be sorted.

    However, I am currently facing a slightly different problem where both a, b are sorted. In this case, there is a more efficient algorithm with complexity n+m using scanning. Does numpy have this algorithm? If not, how should I write code using the current numpy functions with improved efficiency?

    Continue reading...

Compartilhe esta Página