numpy.diagflat() in Python

The diagflat() function of Python numpy class creates a two-dimensional array with the array_like input as a diagonal to the new output array.



a : It represents the array_like input data with diagonal  elements

k: It represents the diagonal value that we require. It is an optional parameter, and its default value is 0. If k>0, the diagonal is above the main diagonal or vice versa.


This function returns the 2-D output array as a diagonal to the new array(ndarray).

Example 1


Pin It on Pinterest

Share This