numpy.diag() in Python

The diag() function of Python numpy class extracts and construct a diagonal array.

Syntax

Parameter

a: It represents the array_like.

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.

Return

This function returns the extracted diagonal or constructed diagonal array.

Example 1

Output

Pin It on Pinterest

Share This