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 Numpy MaskedArray.filled() method - Python numpy.MaskedArray.filled() function return a copy of self, with masked values filled with a given value. However, if there are no masked values to fill, self will be returned instead as an ndarray. Syntax : numpy.MaskedArray.filled(self, fill_value = None) Parameters : fill_value : [scalar, optional 2 min read numpy.full() in Python numpy.full(shape, fill_value, dtype = None, order = 'C') : Return a new array with the same shape and type as a given array filled with a fill_value. Parameters : shape : Number of rows order : C_contiguous or F_contiguous dtype : [optional, float(by Default)] Data type of returned array. fill_value 1 min read Python | sympy.diag() method With the help of sympy.diag() method, we can create a matrix having dimension nxn and filled with numbers in the diagonal by using sympy.diag() method. Syntax : sympy.diag() Return : Return a new matrix. Example #1 : In this example, we can see that by using sympy.diag() method, we are able to creat 1 min read NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read numpy.ndarray.fill() in Python numpy.ndarray.fill() method is used to fill the numpy array with a scalar value. If we have to initialize a numpy array with an identical value then we use numpy.ndarray.fill(). Suppose we have to create a NumPy array a of length n, each element of which is v. Then we use this function as a.fill(v). 2 min read Like