Python | Numpy numpy.choose ()

Using the Numpy numpy.choose () method, we can select items from a multidimensional array by passing an array parameter that contains the index of the line number to be selected. The output array is the same size as the parameter.

Syntax: numpy.choose()

Return: Return an array of element choice

Example # 1:
In this example we can see that using the numpy.choose () method we can extract an array of choices from a multidimensional array.

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = [[ 1 , 2 , 3 , 4 ], [ 3 , 1 , 5 , 6 ]]

 
# using the numpy.choose () method

geeks = np.choose ([ 1 , 0 , 1 , 0 ], gfg)

 

print (geeks)

Exit:

 array ([3 2 5 4]) 

 Example # 2:

Exit:

 array ([7 2 6]) 

# import important module into python

import numpy as np

 
# make a matrix with NumPy

gfg = [[ 1 , 2 , 3 ], [ 4 , 5 , 6 ], [ 7 , 8 , 9 ]]

 
# using the numpy.choose () method

geeks = np.choose ([ 2 , 0 , 1 ], gfg)

 

print (geeks)