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 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 Diagnol elements : \n", geek.diag(a), "\n") print("Diagnol above main diagnol : \n", geek.diag(a, 1), "\n") print("Diagnol below main diagnol : \n", geek.diag(a, -1)) |
chevron_right
filter_none
Output :
Main Diagnol elements : [ 1 434 56] Diagnol above main diagnol : [21 3] Diagnol below main diagnol : [63 54]
References :
https://docs.scipy.org/doc/numpy/reference/generated/numpy.diagflat.html#numpy.diagflat
Note :
These NumPy-Python programs won’t run on onlineID, so run them on your systems to explore them
.
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python - Read blob object in python using wand library
- Python | Convert list to Python array
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- twitter-text-python (ttp) module - Python
- MySQL-Connector-Python module in Python
- Python | Index of Non-Zero elements in Python list
- Python | Merge Python key values to list
- Python | PRAW - Python Reddit API Wrapper
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- set add() in python
- Use of min() and max() in Python
- Python Try Except
- chr() in Python

