[Python] Numpythonic way of the inverse of sliding_window_view

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I have original array test:

    from numpy.lib.stride_tricks import sliding_window_view

    test = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14]).reshape(-1,7) # (batch_size, seq_len) -> (2,7)
    slided = sliding_window_view(test, window_shape=(3,), axis=-1).copy()
    print(test, test.shape)
    print(slided, slided.shape)


    Outputting:

    [[ 1 2 3 4 5 6 7]
    [ 8 9 10 11 12 13 14]] (2, 7)

    [[[ 1 2 3]
    [ 2 3 4]
    [ 3 4 5]
    [ 4 5 6]
    [ 5 6 7]]

    [[ 8 9 10]
    [ 9 10 11]
    [10 11 12]
    [11 12 13]
    [12 13 14]]] (2, 5, 3)


    Given copied of slided array that was computed by sliding_window_view returning shape (batch_size, num_win, win_len), how do I reconstruct back into original array test with the shape of (batch_size, seq_len)?

    Continue reading...

Compartilhe esta Página