Python | Numpy matrix.item ()

With the Numpy matrix.item () method we can get elements from a given matrix, just Numpy matrix .item () the index number, and for a multidimensional matrix we will get the element by specifying a tuple of the index value.

Syntax: matrix.item (index)

Return: Return item from given matrix

Example # 1:
In this example, we see that we can get an element using the matrix.item () method index number.

# import important module in python

import numpy as np

 
# make a matrix with NumPy

gfg  = np.matrix ( '[6, 1; 2, 3] ' )

  
# using the matrix.item () method

geeks = gfg.item (( 1 , 0 ))

 

print (geeks)

Exit :

 2 

Example # 2:

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( ' [1, 2 , 3; 4, 5, 6; 7, 8, 9] ' )

  
# applying the matrix.item () method

geeks = gfg.item (( 2 , 0 ))

  

print (geeks)

Exit :

 7 




Get Solution for free from DataCamp guru