Last Updated : 09 Mar, 2022
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 :
ndarrayPython
# Python Programming illustrating
# numpy.diag method
import numpy as geek
# matrix creation by array input
a = geek.matrix([[1, 21, 30],
[63 ,434, 3],
[54, 54, 56]])
print("Main Diagonal elements : \n", geek.diag(a), "\n")
print("Diagonal above main diagonal : \n", geek.diag(a, 1), "\n")
print("Diagonal below main diagonal : \n", geek.diag(a, -1))
Output :
Main Diagonal elements : [ 1 434 56] Diagonal above main diagonal : [21 3] Diagonal below main diagonal : [63 54]
References :
https://numpy.org/doc/stable/reference/generated/numpy.diagflat.html#numpy.diagflat
Note :
These NumPy-Python programs won't run on online IDE's, so run them on your systems to explore them
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4