np.repeat()
np.repeat用于将numpy数组重复
一维数组重复三次
import numpy as np # 随机生成[0,5)之间的数,形状为(1,4),将此数组重复3次 pop = np.random.randint(0, 5, size=(1, 4)).repeat(3, axis=0) print("pop\n",pop) # pop # [[0 0 3 1] # [0 0 3 1] # [0 0 3 1]]
二维数组在第一维和第二维分别重复三次
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\n",pop_reshape) print("pop_reshape_repeataxis0\n",pop_reshape_repeataxis0) print("pop_reshape_repeataxis1\n",pop_reshape_repeataxis1) # pop_reshape # [[0 0 3 1 0 0] # [3 1 0 0 3 1]] # pop_reshape_repeataxis0 # [[0 0 3 1 0 0] # [0 0 3 1 0 0] # [0 0 3 1 0 0] # [3 1 0 0 3 1] # [3 1 0 0 3 1] # [3 1 0 0 3 1]] # pop_reshape_repeataxis1 # [[0 0 0 0 0 0 3 3 3 1 1 1 0 0 0 0 0 0] # [3 3 3 1 1 1 0 0 0 0 0 0 3 3 3 1 1 1]]
原文链接:https://blog.csdn.net/u013555719/article/details/83855965
原文地址:http://www.cnblogs.com/bokeyuanjj/p/16852545.html
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。