How to replicate array to specific length array

前端 未结 4 1139
半阙折子戏
半阙折子戏 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 12:56

    There are better ways to replicate the array, for example you could simply use np.resize:

    Return a new array with the specified shape.

    If the new array is larger than the original array, then the new array is filled with repeated copies of a. [...]

    >>> import numpy as np
    >>> var = [22,33,44,55]
    >>> n = 13
    >>> np.resize(var, n)
    array([22, 33, 44, 55, 22, 33, 44, 55, 22, 33, 44, 55, 22])
    

提交回复
热议问题