np.repeat() | 您所在的位置:网站首页 › 重复repeat › np.repeat() |
np.repeat()用于将numpy数组重复。 numpy.repeat(a, repeats, axis=None); 参数: axis=0,沿着y轴复制,实际上增加了行数axis=1,沿着x轴复制,实际上增加了列数
1. 一维数组重复3次 # 随机生成[0, 5)之间的数,形状1行4列,将此数组按y轴重复3次 import numpy as np pop = np.random.randint(0, 5, size=(1, 4)).repeat(3, axis=0) print(pop) [[1 4 0 4] [1 4 0 4] [1 4 0 4]]
2. 二维数组在第一维和第二维分别重复3次 # 二维数组在第一维和第二维分别重复3次 pop_reshape = pop.reshape(2, 6) pop_reshape_repeataxis0 = pop_reshape.repeat(3, axis=0) pop_reshape_repeataxis1 = pop_reshape.repeat(3, axis=1) print(pop_reshape) print(pop_reshape_repeataxis0) print(pop_reshape_repeataxis1 ) [[1 4 0 4 1 4] [0 4 1 4 0 4]] [[1 4 0 4 1 4] [1 4 0 4 1 4] [1 4 0 4 1 4] [0 4 1 4 0 4] [0 4 1 4 0 4] [0 4 1 4 0 4]] [[1 1 1 4 4 4 0 0 0 4 4 4 1 1 1 4 4 4] [0 0 0 4 4 4 1 1 1 4 4 4 0 0 0 4 4 4]]
来自:https://blog.csdn.net/u013555719/article/details/83855965 |
CopyRight 2018-2019 实验室设备网 版权所有 |