[Python] How to fill in array in row x from columns 0:N where N is part of an np array

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

  1. Stack

    Stack Membro Participativo

    I have an mxn array, im_arr. im_elev, r, and theta_round are all 1xm arrays (I end up overwriting some columns as im filling in the array).

    I want to fill in im_arr where im_arr[theta_sort, 0:elev] = c

    Is there a way to do this without a for loop (/ what would be the most efficient way to fill in this array?)



    #r sorted is the idx array, sorted for another matrix

    for idx_all in r_sorted:


    elev = im_elev[idx_all] #elevation at idx

    c = (1 - (r[idx_all] / 10813)) // #10813 is maximum r value

    imshow_arr[int(theta_round[idx_all]),0:elev] = c




    worked. However, it takes a long time (r_sorted >> 10,000,000). Id like to avoid the for loop.

    im_arr[idx, 0:elev] = c throws the error IndexError: arrays used as indices must be of integer (or boolean) type

    I'm thinking I could also fill in the array with im_arr[theta_sort, elev] = c then boolean mask the zeros, and have every zero = first non zero value above it. The syntax here has still proven challenging. Any ideas are much appreciated!

    Continue reading...

Compartilhe esta Página