Python| numpy matrix.repeat()
借助Numpy matrix.repeat()
方法,我们可以从给定矩阵中获取重复值,并将输出作为一维数组。
Syntax : matrix.repeat(count)
Return : Return 1-D matrix with repeated values
示例 #1:
在这个例子中,我们可以看到我们能够在方法matrix.repeat()
的帮助下从给定矩阵中获取重复值。
# import the important module in python
import numpy as np
# make matrix with numpy
gfg = np.matrix('[64, 1; 12, 3]')
# applying matrix.repeat() method
geeks = gfg.repeat(2)
print(geeks)
输出:
[[64 64 1 1 12 12 3 3]]
示例 #2:
# import the important module in python
import numpy as np
# make a matrix with numpy
gfg = np.matrix('[1, 2, 3; 4, 5, 6; 7, 8, -9]')
# applying matrix.repeat() method
geeks = gfg.repeat(3)
print(geeks)
输出:
[[ 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8
-9 -9 -9]]