[Python] Creating shifted Hankel matrix

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    Say I have some time-series data in the form of a simple array.

    X1 = np.array[(1, 2, 3, 4]


    The Hankel matrix can be obtained by using scipy.linalg.hankel, which would look something like this:

    hankel(X1)

    # array([[1, 2, 3, 4],
    # [2, 3, 4, 0],
    # [3, 4, 0, 0],
    # [4, 0, 0, 0]])



    Now assume I had a larger array in the form of

    X2 = np.array([1, 2, 3, 4, 5, 6, 7])


    What I want to do is fill in the zeros in this matrix with the numbers that are next in the index (specific to each row). Taking the same Hankel matrix earlier by using the first four values in the array X2, I'd like to see the following output:

    hankel(X2[:4])

    # array([[1, 2, 3, 4],
    # [2, 3, 4, 5],
    # [3, 4, 5, 6],
    # [4, 5, 6, 7]])


    How would I do this? I'd ideally like to use this for larger data. Appreciate any tips or pointers given. Thanks!

    Continue reading...

Compartilhe esta Página