[Python] Most efficient way to allocate n copies of an array to n-new dimensions?

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    The task is to create 361x721x11 copies of ll as fast as possible preferably using the functions in numpy. The following code works

    ll = ones((13,25)) # used ones() for illustration purposes. My real array isn't actually just a bunch of ones
    ll_ijk = np.repeat(np.repeat(np.repeat(ll[...,None,None,None],361,axis = 2),721,axis = 3),11,axis = 4)


    where I used nested calls of the repeat function for each new dimension, but it took about 4-5 seconds to complete. Is there a more/most efficient way of doing this?

    Continue reading...

Compartilhe esta Página