numpy.diagflat() in Python Last Updated : 04 Aug, 2021 Comments Improve Suggest changes Like Article Like Report 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 versa. Returns : array with the array_like input as a diagonal to the new output array. Python # Python Program illustrating # numpy.diagflat method import numpy as geek print("diagflat use on main diagonal : \n", geek.diagflat([1, 7]), "\n") print("diagflat use on main diagonal : \n", geek.diagflat([1, 7, 6]), "\n") # Diagonal above main diagonal print("diagflat above main diagonal : \n", geek.diagflat([1, 7, 6], 1), "\n") Output : diagflat use on main diagonal : [[1 0] [0 7]] diagflat use on main diagonal : [[1 0 0] [0 7 0] [0 0 6]] diagflat above main diagonal : [[0 1 0 0] [0 0 7 0] [0 0 0 6] [0 0 0 0]] Note : These NumPy-Python programs won't run on onlineID, so run them on your systems to explore them. Comment More infoAdvertise with us Next Article numpy.diagflat() in Python M Mohit Gupta_OMG Improve Article Tags : Misc Python Python-numpy Python numpy-arrayCreation Practice Tags : Miscpython 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.fabs() in Python numpy.fabs() function is used to compute the absolute values element-wise. This function returns the absolute values (positive magnitude) of the data in arr. It always return absolute values in floats. Syntax : numpy.fabs(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, u 2 min read numpy.alen() in Python numpy.alen() function is used to return the length of the first dimension of the input array. Syntax : numpy.alen(arr) Parameters : arr : [array_like] Input array. Return : [int]Length of the first dimension of arr. Code #1 : Python3 # Python program explaining # alen() function import numpy as geek 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.identity() in Python numpy.identity() function is used to create an identity matrix which is used to make identity matrix. This is commonly used in linear algebra and numerical computations. It has the following properties:Diagonal elements are all 1s.Non-diagonal elements are all 0s.Syntax: numpy.identity(n, dtype=None 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.hypot() in Python This mathematical function helps user to calculate hypotenuse for the right angled triangle, given its side and perpendicular. Result is equivalent to Equivalent to sqrt(x1**2 + x2**2), element-wise. Syntax : numpy.exp2(arr1, arr2[, out]) = ufunc 'hypot') : Parameters : arr1, arr2 : [array_like] Leg 2 min read numpy.eye() in Python numpy.eye() is a function in the NumPy library that creates a 2D array with ones on the diagonal and zeros elsewhere. This function is often used to generate identity matrices with ones along the diagonal and zeros in all other positions.Let's understand with the help of an example:Pythonimport nump 2 min read numpy.cos() in Python numpy.cos(x[, out]) = ufunc 'cos') : This mathematical function helps user to calculate trigonometric cosine for all x(being the array elements). Parameters : array : [array_like]elements are in radians. 2pi Radians = 360 degrees Return : An array with trigonometric cosine of x for all x i.e. array 2 min read numpy.exp2() in Python numpy.exp2(array, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : This mathematical function helps user to calculate 2**x for all x being the array elements. Parameters : array : [array_like]Input array or object whose elements, we need to test. out : [ndarray, optional 2 min read Like