[Python] Is there an equivalent of np.roll() in DolphinDB?

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

  1. Stack

    Stack Membro Participativo

    In Python’s NumPy, np.roll() allows shifting array elements along an axis, where elements that roll beyond the last position wrap around to the first (e.g., np.roll([1, 2, 3], 1) → [3, 1, 2]).

    I tried DolphinDB’s move() function, but it doesn’t seem to support circular shifting (i.e., elements shifted past the end don’t wrap around to the beginning). Example of what I need:

    // Desired behavior (like np.roll):
    input = [1, 2, 3, 4, 5]
    rolled = roll(input, 2) // Expected: [4, 5, 1, 2, 3]


    What I tried with move():

    move([1, 2, 3, 4, 5], 2) // Returns [,,1,2,3], but I need [4,5,1,2,3]


    Does DolphinDB have a built-in function for circular shifting (like np.roll())? If not, what is the most efficient way to implement this (e.g., using vector operations or a custom function)?

    Continue reading...

Compartilhe esta Página