[Python] Sampling numpy array with float indices (similar to pytorch grid_sample)

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

  1. Stack

    Stack Membro Participativo

    Is there some way of sampling a numpy array with float indices, using bilinear interpolation to get the intermediate values? For example, given the 1D array:

    arr=np.array([0,1])


    I would like arr[0.5] to return 0.5, since that index lies between 0 and 1. For a 2D example:

    arr=np.array([[0,1],[2,3]])


    arr[0.5, 0.5] should return 1.5. In pytorch this functionality is provided by torch.nn.grid_sample, I'd like to compare performance to doing this in numpy for my application.

    Continue reading...

Compartilhe esta Página