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)

 

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 )

 

 

 来自:https://blog.csdn.net/u013555719/article/details/83855965

posted @ 2019-07-25 20:36  做梦当财神  阅读(11412)  评论(0编辑  收藏  举报