How to replicate a row of an array with numpy?

前端 未结 2 1950
醉梦人生
醉梦人生 2021-01-27 00:26

I want to replicate the last row of an array in python and found the following lines of code in the numpy documentation

>>> x = np.array([[1,2],[3,4]])         


        
2条回答
  •  再見小時候
    2021-01-27 00:55

    I have test it using following code

        >>> a
        array([[1, 2],
               [3, 4]])
        >>> np.repeat(a, [2,3], axis = 0)
        array([[1, 2],
               [1, 2],
               [3, 4],
               [3, 4],
               [3, 4]])
        >>> np.repeat(a, [1,3], axis = 0)
        array([[1, 2],
               [3, 4],
               [3, 4],
               [3, 4]])
    

    The second parameter seems mean how many times the i-th elements in a will be repeat. As my code shown above, [2,3] repeats a[0] 2 times and repeats a[1] 3 times, [1,3] repeats a[0] 1 times and repeats a[1] 3 times

提交回复
热议问题