Python | numpy.fill_diagonal() method Last Updated : 27 Sep, 2019 Comments Improve Suggest changes Like Article Like Report 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 we can see that by using numpy.fill_diagonal() method, we are able to get the diagonals filled with the values passed as parameter. Python3 1=1 # import numpy import numpy as np # using numpy.fill_diagonal() method array = np.array([[1, 2], [2, 1]]) np.fill_diagonal(array, 5) print(array) Output : [[5 2] [2 5]] Example #2 : Python3 1=1 # import numpy import numpy as np # using numpy.fill_diagonal() method array = np.zeros((3, 3), int) np.fill_diagonal(array, 1) print(array) Output : [[1 0 0] [0 1 0] [0 0 1]] Comment More infoAdvertise with us Next Article Python | numpy.fill_diagonal() method J jitender_1998 Follow Improve Article Tags : Python Python-numpy Practice Tags : python Similar Reads 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 # Python Programming illustrating # numpy.diag method import numpy as geek 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_indices() in Python The numpy.diag_indices() function returns indices in order to access the elements of main diagonal of a array with minimum dimension = 2. Returns indices in the form of tuple. to access the main diagonal of an array. Syntax: numpy.diag_indices(n, n_dim = 2) Parameters : n : size of array, for whic 2 min read numpy.insert() in Python The numpy.insert() function inserts values along the mentioned axis before the given indices. Syntax : numpy.insert(array, object, values, axis = None) Parameters : array : [array_like]Input array. object : [int, array of ints]Sub-array with the index or indices before which values is inserted val 4 min read Python sympy | Matrix.diagonalize() method With the help of sympy.Matrix().diagonalize() method, we can diagonalize a matrix. diagonalize() returns a tuple (P, D), where D is diagonal and M = PDP^{-1}. Syntax: Matrix().diagonalize() Returns: Returns a tuple of matrix where the second element represents the diagonal of the matrix. Example #1: 1 min read Like