📜  Python| numpy matrix.take()

📅  最后修改于: 2022-05-13 01:54:19.010000             🧑  作者: Mango

Python| numpy matrix.take()

借助Numpy matrix.take()方法,我们可以通过将参数作为该元素的索引值传递来从给定矩阵中选择元素。它将返回一个具有一维的矩阵。请记住,它一次只适用于一个轴。

示例 #1:
在这个例子中,我们可以看到,通过选择一个索引,通过使用matrix.take()方法,我们只能在矩阵中获得一个值。

# import the important module in python
import numpy as np
              
# make matrix with numpy
gfg = np.matrix('[4, 1, 12, 3, 4, 6, 7]')
              
# applying matrix.take() method
geek = gfg.take(2)
    
print(geek)
输出:
[[12]]

示例 #2:

# import the important module in python
import numpy as np
              
# make matrix with numpy
gfg = np.matrix('[4, 1, 9; 12, 3, 1; 4, 5, 6]')
              
# applying matrix.take() method
geek = gfg.take(0, 1)
    
print(geek)
输出:
[[ 4 12  4]]