np.repeat()学习

1.np.repeat 

https://blog.csdn.net/u010496337/article/details/50572866/

import numpy as np
a=np.array(([1,2],[3,4]))
print(np.repeat(a,2))

#结果:
[1 1 2 2 3 3 4 4]

当axis=None时,会展平为一个行向量。

如果指定轴:

print(np.repeat(a,2,axis=0))

#结果
[[1 2]
 [1 2]
 [3 4]
 [3 4]]

例子2,针对一维向量的repeat:

import numpy as np
a=np.array(([1,2,3,4]))
print(a.reshape(-1,1).repeat(5,1))

#输出:
[[1 1 1 1 1]
 [2 2 2 2 2]
 [3 3 3 3 3]
 [4 4 4 4 4]]

 

posted @ 2022-01-25 11:09  lypbendlf  阅读(163)  评论(0编辑  收藏  举报