📜  Python| numpy numpy.choose()

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

Python| numpy numpy.choose()

Numpy numpy.choose()方法的帮助下,我们可以通过将参数作为包含要选择的行号索引的数组传递来从多维数组中选择元素。与参数中传递的大小相同的输出数组。

示例 #1:
在这个例子中,我们可以看到在numpy.choose()方法的帮助下,我们能够从多维数组中提取一个选择数组。

# import the important module in python
import numpy as np
             
# make a matrix with numpy
gfg = [[1, 2, 3, 4], [3, 1, 5, 6]]
             
# applying numpy.choose() method
geeks = np.choose([1, 0, 1, 0], gfg)
       
print(geeks)
输出:
array([3 2 5 4])

示例 #2:

# import the important module in python
import numpy as np
             
# make a matrix with numpy
gfg = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
             
# applying numpy.choose() method
geeks = np.choose([2, 0, 1], gfg)
       
print(geeks)
输出:
array([7 2 6])