Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
numpy.diag() in Python
Next article icon

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  elementsstrong>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 methodimportnumpyasgeekprint("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 diagonalprint("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.

 
 


M

Mohit Gupta
Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp