Python| numpy matrix.getfield()
借助Numpy matrix.getfield()
方法,我们可以获得字段矩阵,这意味着字段是矩阵的视图,具有与给定矩阵相同大小的给定数据类型。
Syntax : matrix.getfield()
Return : Return field matrix
示例 #1:
在这个例子中,我们可以看到我们能够在方法matrix.getfield()
的帮助下获取字段矩阵。
# import the important module in python
import numpy as np
# make matrix with numpy
gfg = np.matrix('[6, 1; 2, 3]')
# applying matrix.getfield() method
geeks = gfg.getfield(int)
print(geeks)
输出:
[[6 1]
[2 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.getfield() method
geeks = gfg.getfield(int)
print(geeks)
输出:
[[1 2 3]
[4 5 6]
[7 8 9]]