[Python] np.concatenate extremely slow for slightly larger 2D ndarray while small slices run...

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    I encountered extremely slow performance when calling np.concatenate. The minimal reproducible code is as follows:

    a = np.zeros((1200, 500), dtype=np.float64)

    # Runs instantly, under 1 second
    b = np.concatenate(a[:1000])

    # Extremely slow, takes ~10 minutes
    c = np.concatenate(a)


    np.concatenate(a) (just slightly larger) is extremely slow, even though memory usage is small.

    I know there are some faster alternatives, but I'm curious why this behavior occurs.

    Is this extremely slow behavior expected for np.concatenate? Why?

    Continue reading...

Compartilhe esta Página