How to replicate array to specific length array

前端 未结 4 1141
半阙折子戏
半阙折子戏 2020-12-03 12:39

I want replicate a small array to specific length array

Example:

var = [22,33,44,55] # ==> len(var) = 4
n = 13

The new array tha

4条回答
  •  一生所求
    2020-12-03 13:13

    var = [22,33,44,55]
    n = 13
    

    Repeating a list (or any other iterable) can be done without numpy, using itertools's cycle() and islice() functions

    from itertools import cycle, islice
    var_new = list(islice(cycle(var),0,n)
    

提交回复
热议问题