Python | Numpy matrix.item() (original) (raw)
Last Updated : 15 Apr, 2019
With the help of **Numpy matrix.item()**
method, we can get the items from a given matrix by just providing index number and for multidimensional matrix we get the item by giving tuple of index value.
Syntax :
matrix.item(index)
Return : Return item from given matrix
Example #1 :
In this example we can see that we are able to get the item with the help of method matrix.item()
by providing index number.
import
numpy as np
gfg
=
np.matrix(
'[6, 1; 2, 3]'
)
geeks
=
gfg.item((
1
,
0
))
print
(geeks)
Example #2 :
import
numpy as np
gfg
=
np.matrix(
'[1, 2, 3; 4, 5, 6; 7, 8, 9]'
)
geeks
=
gfg.item((
2
,
0
))
print
(geeks)
Similar Reads
- numpy.matrix() in Python This class returns a matrix from a string of data or array-like object. Matrix obtained is a specialised 2D array. Syntax : numpy.matrix(data, dtype = None) : Parameters : data : data needs to be array-like or string dtype : Data type of returned array. Returns : data interpreted as a matrix # Pytho 1 min read
- Python | Numpy ndarray.item() With the help of numpy.ndarray.item() method, we can fetch the data elements that is found at the given index on numpy array. Remember we can give index as one dimensional parameter or can be two dimensional. Parameters: *args : Arguments (variable number and type) -> none: This argument only works 1 min read
- Python | Numpy matrix.take() With the help of Numpy matrix.take() method, we can select the elements from a given matrix by passing the parameter as index value of that element. It will return a matrix having one dimension. Remember it will work for one axis at a time. Syntax : matrix.take(index, axis) Return : Return matrix of 1 min read
- numpy.asmatrix() in Python numpy.asmatrix(data, dtype = None) Returns a matrix by interpreting the input as a matrix. Parameters : data : array-like input data dtype : Data type of returned array Returns : Interprets the input as a matrix # Python Programming illustrating # numpy.asmatrix import numpy as geek # array-like inp 1 min read
- numpy.matrix.A() function - Python numpy.matrix.A() function return self as an ndarray object. Syntax : numpy.matrix.A() Parameters : None Return : [ndarray] Return self as an ndarray. Code #1 : # Python program explaining # numpy.matrix.A() function # importing numpy as geek import numpy as geek mat = geek.matrix(geek.arange(9).resh 1 min read
- Python | Numpy numpy.matrix.A() With the help of Numpy numpy.matrix.A() method, we can get the same matrix as self. It means through this method we can get the identical matrix. Syntax : numpy.matrix.A() Return : Return self matrix Example #1 : In this example we can see that with the help of matrix.A() method, we are able to get 1 min read
- Numpy matrix.I function | Python With the help ofnumpy.matrix.I() function we can get the multiplicative inverse of the same size as of our given matrix. Syntax : numpy.matrix.I() Return : [matrix object] If self is non-singular, ret is such that ret * self == self * ret == np.matrix(np.eye(self[0, :].size) all return True. Return 1 min read
- Python | Numpy matrix.tolist() With the help of Numpy matrix.tolist() method, we are able to convert the matrix into a list by using the matrix.tolist() method. Syntax: matrix.tolist() Return : Return a new list Example #1 : In this example we can see that by passing the matrix we are able to convert it into list by using the mat 1 min read
- numpy.empty() in Python numpy.empty(shape, dtype = float, order = 'C') : Return a new array of given shape and type, with random values. Parameters : -> shape : Number of rows -> order : C_contiguous or F_contiguous -> dtype : [optional, float(by Default)] Data type of returned array. # Python Programming illustra 1 min read
- Python | Numpy numpy.matrix.any() With the help of Numpy numpy.matrix.any() method, we are able to compare each and every element of one matrix with another or we can provide the axis on the we want to apply comparison if any of the element matches it return true. Syntax : numpy.matrix.any() Return : Return true if any match found e 1 min read