numpy.repeat#
- numpy.repeat(a, repeats, axis=None)[原始碼]#
重複陣列中每個元素自身之後
- 參數:
- aarray_like
輸入陣列。
- repeatsint 或 int 陣列
每個元素的重複次數。repeats 會被廣播以符合給定軸的形狀。
- axisint,可選
沿著哪個軸重複值。預設情況下,使用扁平化的輸入陣列,並返回扁平化的輸出陣列。
- 返回:
- repeated_arrayndarray
輸出陣列,其形狀與 a 相同,除了給定軸之外。
範例
>>> import numpy as np >>> np.repeat(3, 4) array([3, 3, 3, 3]) >>> x = np.array([[1,2],[3,4]]) >>> np.repeat(x, 2) array([1, 1, 2, 2, 3, 3, 4, 4]) >>> np.repeat(x, 3, axis=1) array([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]) >>> np.repeat(x, [1, 2], axis=0) array([[1, 2], [3, 4], [3, 4]])