Python | Numpy matrix.take ()



Using the Numpy matrix.take () method, we can select elements from a given matrix by passing a parameter as the index value of that element. It will return a matrix that has one dimension. Remember this will work for one axis at a time.

Syntax: matrix.take (index, axis)
Return: Return matrix of selected indexes

Example # 1:
In this example, we we see that by choosing one index, we get only one value in the matrix using matrix.take () .

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[4, 1, 12, 3 , 4, 6, 7] ` )

  
# using the matrix.take () method

geek = gfg.take ( 2 )

 

print (geek)

Output:

 [[12]] 

Example # 2:

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# using the matrix.take () method

geek = gfg.take ( 0 , 1 )

 

print (geek)

Exit:

 [[4 12 4]]