Python | Numpy matrix.choose ()

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

Syntax: matrix.choose()

Return: Return an array of element choice

Example # 1:
In this example we can see that using the matrix.choose () method we can extract an array of options from the matrix.

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[1, 2, 3, 4; 3, 1, 5, 6] ` )

  
# using the matrix.choose () method

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

  

print (geeks)

Exit:

 [[3 2 5 4]] 

Example # 2:

# import 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] ` )

  
# using the matrix.choose () method

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

 

print (geeks)

Exit:

 [[7 2 6]]