Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Charles Parr

Charles Parr

Community Learner
Share
87Questions
85Answers
115.9KViews on questions

How to convert a column or row matrix to a diagonal matrix in Python?

For getting your desired output ,you can try python diagonal matrix method like this: import numpy as np a = np.array([1,2,3,4]) d = np.diag(a) # or simpler: d = np.diag([1,2,3,4]) print(d) Results in: [[1 0 0 0] [0 2 0 0] [0 0 3 0] [0 0 0 4]] If you have a row vector, you can do this: a = np.array([[1, 2, 3, 4]]) d =…

Python

Answered Apr 14, 2021 · 1.1K Views Read answer →

More members from the Java community

Learners asking and answering questions on the same topics — follow their questions and join in.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.