Python | Numpy matrix.diagonal() (original) (raw)
Last Updated : 12 Apr, 2019
With the help of **Numpy matrix.diagonal()**
method, we are able to find a diagonal element
from a given matrix and gives output as one dimensional matrix.
Syntax :
matrix.diagonal()
Return : Return diagonal element of a matrix
Example #1 :
In this example we can see that with the help of matrix.diagonal()
method we are able to find the elements in a diagonal of a matrix.
import
numpy as np
gfg
=
np.matrix(
'[6, 2; 3, 4]'
)
geeks
=
gfg.diagonal()
print
(geeks)
Example #2 :
import
numpy as np
gfg
=
np.matrix(
'[1, 2, 3; 4, 5, 6; 7, 8, 9]'
)
geeks
=
gfg.diagonal()
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
- numpy.diagflat() in Python numpy.diagflat (a, k = 0): Create a two-dimensional array with the array_like input as a diagonal to the new output array. Parameters : a : array_like input data with diagonal elements strong>k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice 1 min read
- numpy.diag() in Python numpy.diag(a, k=0) : Extracts and construct a diagonal array Parameters : a : array_like k : [int, optional, 0 by default] Diagonal we require; k>0 means diagonal above main diagonal or vice versa. Returns : ndarray Python Code # Python Programming illustrating # numpy.diag method import numpy as 1 min read
- Python | numpy.fill_diagonal() method With the help of numpy.fill_diagonal() method, we can get filled the diagonals of numpy array with the value passed as the parameter in numpy.fill_diagonal() method. Syntax : numpy.fill_diagonal(array, value) Return : Return the filled value in the diagonal of an array. Example #1 : In this example 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
- 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
- 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
- Python | Numpy numpy.matrix.all() With the help of Numpy numpy.matrix.all() 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. Syntax : numpy.matrix.all() Return : Return true if found match else false Example #1 : In this example we can see 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
- Python | Numpy matrix.std() With the help of matrix.std() method, we are able to find the standard deviation a matrix by using the same method. Syntax : matrix.std() Return : Return standard deviation of a matrix Example #1 : In this example we are able to find the standard deviation of a matrix by using matrix.std() method. # 1 min read