np.repeat() 用法

1.单词

repeat:重复相关的词义

2.使用

np.repeat(1, 5)
array([1, 1, 1, 1, 1])
# 1 重复5次
 
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]])
# 将重复操作施加到 维度‘axis=1’上,相当于‘增加列数’
 
np.repeat(x, [1, 2], axis=0)
array(
[[1, 2],
[3, 4],
[3, 4]]
)
# 将重复操作施加到 维度‘axis=0’上,相当于‘增加行数’,重复的次数,分别为一次和两次
 

 

转载:https://blog.csdn.net/Bboy_LaiNiao/article/details/117262777
posted @ 2022-06-08 11:04  海_纳百川  阅读(207)  评论(0编辑  收藏  举报
本站总访问量